UNPKG

@broadcom/endevor-bridge-for-git-for-zowe-cli

Version:

Endevor Bridge for Git plug-in for Zowe CLI

111 lines 5.73 kB
"use strict"; /* * Copyright (c) 2019 Broadcom. All Rights Reserved. The term * "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. * * This software and all information contained therein is * confidential and proprietary and shall not be duplicated, * used, disclosed, or disseminated in any way except as * authorized by the applicable license agreement, without the * express written permission of Broadcom. All authorized * reproductions must be marked with this language. * * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO * THE EXTENT PERMITTED BY APPLICABLE LAW, BROADCOM PROVIDES THIS * SOFTWARE WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT * LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL BROADCOM * BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY LOSS OR * DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE, * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS * INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF BROADCOM IS * EXPRESSLY ADVISED OF SUCH LOSS OR DAMAGE. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WorkAreaReserve = void 0; const imperative_1 = require("@zowe/imperative"); const object_1 = require("../../../utils/object"); const BuildUtils_1 = require("../../utils/BuildUtils"); const EndevorService_1 = require("../../service/EndevorService"); const EndevorResponseType_1 = require("../../utils/EndevorResponseType"); const EndevorResponseUtils_1 = require("../../utils/EndevorResponseUtils"); /** * Functions used for reserve a work area. Called by WorkAreaReserve.Handler */ class WorkAreaReserve { /** * Reserves the first work area that is available in the list * * @param workAreas * @param endevorInstance * @param endevorSession * @param task * @throws an error if none is available * @returns the work area that was reserved */ static reserveFirstAvailableWorkArea(workAreas, endevorInstance, endevorSession, task) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace(`WorkAreaReserve - Loop through the work areas and get the Id of first unreserved one.`); const taskPerWorkArea = (imperative_1.TaskProgress.EIGHTY_PERCENT / workAreas.length); for (const workArea of workAreas) { if ((0, object_1.isNotNil)(task)) { task.statusMessage = `Checking if any work area is available (${workAreas.indexOf(workArea)} of ${workAreas.length})`; task.percentComplete += taskPerWorkArea; } const reservedWorkArea = yield WorkAreaReserve.reserveWorkArea(workArea, endevorInstance, endevorSession, false); if ((0, object_1.isNotNil)(reservedWorkArea)) { return reservedWorkArea; } } throw new imperative_1.ImperativeError({ msg: `No work area available. Please try later...` }); }); } /** * Reserves a work area from * * @param workArea work area to reserve * @param endevorInstance endevor instance * @param endevorSession endevor session * @param throwErrorIfFail if true, it throws ImperativeError to stop the command execution * @returns the work area if it was reserved successfully */ static reserveWorkArea(workArea, endevorInstance, endevorSession, throwErrorIfFail = true) { return __awaiter(this, void 0, void 0, function* () { imperative_1.Logger.getAppLogger().trace(`WorkAreaReserve - Try to reserve work area with id: ${workArea.id}`); const elementSpec = BuildUtils_1.BuildUtils.getLockElementSpec(workArea, endevorInstance); const postFormData = { fromFile: " ", ccid: "reserve", comment: "Reserve for developer build", oveSign: "yes" }; const response = yield EndevorService_1.EndevorService.addElement(endevorSession, endevorInstance, elementSpec, postFormData); if (EndevorResponseUtils_1.EndevorResponseUtils.is(response, EndevorResponseType_1.EndevorResponseType.SUCCESSFUL)) { return workArea; } else if (throwErrorIfFail) { if (EndevorResponseUtils_1.EndevorResponseUtils.is(response, EndevorResponseType_1.EndevorResponseType.ELEMENT_IS_ALREADY_PRESENT)) { throw new imperative_1.ImperativeError({ msg: `Failed to reserve work area '${workArea.id}'. It was already reserved.` }); } else { EndevorResponseUtils_1.EndevorResponseUtils.throwError(response, `Failed to reserve work area '${workArea.id}'`); } } }); } } exports.WorkAreaReserve = WorkAreaReserve; //# sourceMappingURL=WorkAreaReserve.js.map