Search in sources :

Example 31 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class SyncInfoBuilder method removableVersions.

/**
 * Get the list of removable versions in the local repository
 *
 * @param local the local repository information
 * @param forceRemove whether versions should be in the list if
 *            they can be fore removed
 * @return the list of software versions that can be removed from the local repository
 * @throws IOException
 */
public static SyncInfo removableVersions(final RepositoryInfo local, final boolean forceRemove) throws IOException {
    final SoftwareVersion localCurrent = (local != null) ? local.getCurrentVersion() : null;
    final List<SoftwareVersion> localVersions = (local != null && local.getVersions() != null) ? local.getVersions() : new ArrayList<SoftwareVersion>();
    return new SyncInfo(findToRemove(localVersions, localCurrent, null, null, forceRemove));
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion)

Example 32 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class UpgradeManager method updateCurrentVersion.

private void updateCurrentVersion(SoftwareVersion targetVersion) throws Exception {
    log.info("Step4: Got reboot lock. Update target version one more time");
    // retrieve the target version once again, since it might have been changed (reverted to be specific)
    // by the first upgraded node holding the lock during upgrade from 2.0/2.1 to 2.2.
    targetInfo = coordinator.getTargetInfo(RepositoryInfo.class);
    SoftwareVersion newTargetVersion = targetInfo.getCurrentVersion();
    if (!targetVersion.equals(newTargetVersion)) {
        log.warn("Step4: target version has changed (was: {}, now is: {}). Aborting version change.", targetVersion, newTargetVersion);
    } else {
        log.info("Step4: Switching to version: {}", newTargetVersion);
        localRepository.setCurrentVersion(targetVersion);
        reboot();
    }
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo)

Example 33 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class UpgradeManager method innerRun.

@Override
protected void innerRun() {
    // need to distinguish persistent locks acquired from UpgradeManager/VdcManager/PropertyManager
    // otherwise they might release locks acquired by others when they start
    final String svcId = String.format("%s,upgrade", coordinator.getMySvcId());
    isValidRepo = localRepository.isValidRepository();
    addRepositoryInfoListener();
    while (doRun) {
        log.debug("Main loop: Start");
        shortSleep = false;
        // Step1: check if we have the reboot lock
        boolean hasLock;
        try {
            hasLock = hasUpgradeLock(svcId);
        } catch (Exception e) {
            log.info("Step1: Failed to verify if the current node has the reboot lock ", e);
            retrySleep();
            continue;
        }
        if (hasLock) {
            try {
                releaseUpgradeLock(svcId);
                log.info("Step1: Released reboot lock for node: {}", svcId);
                wakeupOtherNodes();
            } catch (Exception e) {
                log.info("Step1: Failed to release the reboot lock and will retry: {}", e.getMessage());
                retrySleep();
                continue;
            }
        }
        // Step2: publish current state, and set target if empty
        try {
            initializeLocalAndTargetInfo(svcId);
        } catch (Exception e) {
            log.info("Step2b failed and will be retried: {}", e.getMessage());
            retrySleep();
            continue;
        }
        // Step3: syncing repository
        final SyncInfo syncinfo = getSyncInfoCommon(localInfo, targetInfo);
        if (!syncinfo.isEmpty()) {
            // Step3: nodeInSync discovery
            String controlNodeInSync = null;
            try {
                controlNodeInSync = getAControlNodeInSync(targetInfo);
                log.info("Step3: Control node in syc: {}", controlNodeInSync);
            } catch (Exception e) {
                log.info("Step3 failed and will be retried: {}", e.getMessage());
                retrySleep();
                continue;
            }
            // check and update images
            boolean waitSyncingFinish = syncNodes(syncinfo, controlNodeInSync, svcId);
            if (waitSyncingFinish) {
                retrySleep();
                continue;
            } else {
                // For restored cluster or redeployed node, the image files don't exist.it will need to download
                // the upgrade image from the remote repository. If the node can't connenct with the repository,
                // or the image doesn't exist in it, syssvc would keep throwing exceptions and restart.
                // So here break the syncing and it will retry in next check loop(loopInterval=10mins).
                log.info("Step3: Give up syncing upgrade image, and will retry in next check loop");
            }
        }
        // Step4: if target version is changed, update
        log.info("Step4: If target version is changed, update");
        final SoftwareVersion currentVersion = localInfo.getCurrentVersion();
        final SoftwareVersion targetVersion = targetInfo.getCurrentVersion();
        if (currentVersion != null && targetVersion != null && !currentVersion.equals(targetVersion)) {
            log.info("Step4: Current version: {} != target version: {}. Switch version.", currentVersion, targetVersion);
            // for standby site, check if the active site is stable and the local site is STANDBY_SYNCED
            if (drUtil.isStandby()) {
                if (!coordinator.isActiveSiteHealthy()) {
                    log.info("current site is standby and active site is not stable, sleep 1m and try again");
                    sleep(STANDBY_UPGRADE_RETRY_INTERVAL);
                    continue;
                }
                SiteState localSiteState = drUtil.getLocalSite().getState();
                if (!localSiteState.equals(SiteState.STANDBY_SYNCED) && !localSiteState.equals(SiteState.STANDBY_INCR_SYNCING)) {
                    log.info("current site is standby and is in state {}, sleep 1m and try again", localSiteState);
                    sleep(STANDBY_UPGRADE_RETRY_INTERVAL);
                    continue;
                }
            }
            try {
                if (!getUpgradeLock(svcId)) {
                    retrySleep();
                    continue;
                }
                if (!isQuorumMaintained()) {
                    releaseUpgradeLock(svcId);
                    retrySleep();
                    continue;
                }
                updateCurrentVersion(targetVersion);
            } catch (Exception e) {
                log.info("Step4: Upgrade failed and will be retried: {}", e.getMessage());
                // Restart the loop immediately so that we release the reboot lock.
                continue;
            }
        }
        // Step6: sleep
        log.info("Step6: sleep");
        longSleep();
    }
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) SiteState(com.emc.storageos.coordinator.client.model.SiteState) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException)

Example 34 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class UpgradeService method getImage.

/**
 * *Internal API, used only between nodes*
 * <p>
 * Get image
 *
 * @param versionStr Version to be retrieved
 * @return Image details
 */
@GET
@Path("internal/image/")
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public Response getImage(@QueryParam("version") String versionStr) {
    _log.info("getImage({})", versionStr);
    final SoftwareVersion version;
    try {
        version = new SoftwareVersion(versionStr);
    } catch (InvalidSoftwareVersionException e) {
        throw APIException.badRequests.parameterIsNotValid("version");
    }
    final InputStream in;
    try {
        in = LocalRepository.getInstance().getImageInputStream(version);
    } catch (LocalRepositoryException e) {
        throw APIException.internalServerErrors.getObjectFromError("image input stream", "local repository", e);
    }
    return Response.ok(in).type(MediaType.APPLICATION_OCTET_STREAM).build();
}
Also used : InvalidSoftwareVersionException(com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) InputStream(java.io.InputStream) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 35 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class UpgradeService method uploadImage.

/**
 * Upload the image file given.
 * Consumes MediaType.APPLICATION_OCTET_STREAM.
 * This is an asynchronous operation.
 *
 * @brief Upload the specified image file
 * @prereq Cluster state should be STABLE
 * @return Cluster information.
 */
@POST
@Path("image/upload")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Consumes({ MediaType.APPLICATION_OCTET_STREAM })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response uploadImage(@Context HttpServletRequest request) {
    File file = null;
    String svcId = _coordinator.getMySvcId();
    _log.info("uploadImage to {} start", svcId);
    // validate
    if (!_coordinator.isClusterUpgradable()) {
        throw APIException.serviceUnavailable.clusterStateNotStable();
    }
    // maximal install number check
    RepositoryInfo targetInfo = null;
    try {
        targetInfo = _coordinator.getTargetInfo(RepositoryInfo.class);
    } catch (Exception e) {
        throw APIException.internalServerErrors.getObjectFromError("target repository info", "coordinator", e);
    }
    if (targetInfo.getVersions().size() > SyncInfoBuilder.MAX_SOFTWARE_VERSIONS) {
        throw APIException.badRequests.numberOfInstalledExceedsMax();
    }
    // length check
    String contentLength = request.getHeader("Content-Length");
    if (Long.parseLong(contentLength) <= 0 || Long.parseLong(contentLength) > MAX_UPLOAD_SIZE) {
        throw APIException.badRequests.fileSizeExceedsLimit(MAX_UPLOAD_SIZE);
    }
    try {
        // remove previous and upload to a temp file
        UpgradeImageUploader uploader = UpgradeImageUploader.getInstance(_upgradeManager);
        uploader.cleanUploadFiles();
        long versionSize = Long.valueOf(contentLength);
        _log.info("The size of the image is:" + versionSize);
        String version = VIPR_UNKNOWN_IMAGE_VERSION;
        initializeDownloadProgress(version, versionSize);
        file = uploader.startUpload(request.getInputStream(), version);
        // install image
        if (file == null || file != null && !file.exists()) {
            throw APIException.internalServerErrors.targetIsNullOrEmpty("Uploaded file");
        }
        version = _upgradeManager.getLocalRepository().installImage(file);
        // set target
        List<SoftwareVersion> newList = new ArrayList<SoftwareVersion>(targetInfo.getVersions());
        SoftwareVersion newVersion = new SoftwareVersion(version);
        if (newList.contains(newVersion)) {
            _log.info("Version has already been installed");
        } else {
            newList.add(newVersion);
            _coordinator.setTargetInfo(new RepositoryInfo(targetInfo.getCurrentVersion(), newList));
            DownloadingInfo temp = _coordinator.getNodeGlobalScopeInfo(DownloadingInfo.class, DOWNLOADINFO_KIND, svcId);
            _coordinator.setNodeGlobalScopeInfo(new DownloadingInfo(version, versionSize, versionSize, DownloadStatus.COMPLETED, temp._errorCounter), DOWNLOADINFO_KIND, svcId);
            _coordinator.setTargetInfo(new DownloadingInfo(version, versionSize), false);
        }
        _log.info("uploadImage to {} end", svcId);
        auditUpgrade(OperationTypeEnum.UPLOAD_IMAGE, AuditLogManager.AUDITLOG_SUCCESS, null, targetInfo.getCurrentVersion().toString(), svcId);
        // return cluster status
        ClusterInfo clusterInfo = _coordinator.getClusterInfo();
        if (clusterInfo == null) {
            throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster info");
        }
        return toClusterResponse(clusterInfo);
    } catch (APIException ae) {
        throw ae;
    } catch (Exception e) {
        throw APIException.internalServerErrors.uploadInstallError(e);
    } finally {
        if (file != null && file.exists()) {
            file.delete();
        }
    }
}
Also used : DownloadingInfo(com.emc.storageos.coordinator.client.model.DownloadingInfo) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) ArrayList(java.util.ArrayList) File(java.io.File) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) ServiceUnavailableException(com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException) InvalidSoftwareVersionException(com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) IOException(java.io.IOException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

SoftwareVersion (com.emc.storageos.coordinator.client.model.SoftwareVersion)44 RepositoryInfo (com.emc.storageos.coordinator.client.model.RepositoryInfo)12 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)10 InvalidSoftwareVersionException (com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException)9 RemoteRepositoryException (com.emc.storageos.systemservices.exceptions.RemoteRepositoryException)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 Path (javax.ws.rs.Path)8 LocalRepositoryException (com.emc.storageos.systemservices.exceptions.LocalRepositoryException)7 IOException (java.io.IOException)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 ServiceUnavailableException (com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException)6 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)6 ClusterInfo (com.emc.vipr.model.sys.ClusterInfo)5 File (java.io.File)5 Produces (javax.ws.rs.Produces)5 InputStream (java.io.InputStream)4 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)3 POST (javax.ws.rs.POST)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3