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));
}
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();
}
}
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();
}
}
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();
}
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();
}
}
}
Aggregations