use of com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException in project coprhd-controller by CoprHD.
the class UpgradeService method installImage.
/**
* Install image. Image can be installed only if the number of installed images are less than MAX_SOFTWARE_VERSIONS
*
* @brief Install image
* @param versionStr Version to be installed
* @prereq Cluster state should be STABLE
* @return Cluster state information
* @throws Exception
*/
@POST
@Path("image/install/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response installImage(@QueryParam("version") String versionStr) throws Exception {
_log.info("installImage({})", versionStr);
final SoftwareVersion version;
try {
version = new SoftwareVersion(versionStr);
} catch (InvalidSoftwareVersionException e) {
throw APIException.badRequests.parameterIsNotValid("version");
}
// do not proceed if there's paused sites.
checkClusterState(false);
RepositoryInfo repoInfo = null;
try {
repoInfo = _coordinator.getTargetInfo(RepositoryInfo.class);
} catch (Exception e) {
throw APIException.internalServerErrors.getObjectFromError("target repository info", "coordinator", e);
}
SoftwareVersion currentVersion = repoInfo.getCurrentVersion();
List<SoftwareVersion> localAvailableVersions = repoInfo.getVersions();
if (localAvailableVersions.size() > SyncInfoBuilder.MAX_SOFTWARE_VERSIONS) {
throw APIException.badRequests.numberOfInstalledExceedsMax();
}
RemoteRepository repo = _upgradeManager.getRemoteRepository();
if (isInstalled(repoInfo.getVersions(), version)) {
throw APIException.badRequests.versionIsInstalled(versionStr);
}
if (!isUpgradable(repoInfo.getCurrentVersion(), version)) {
throw APIException.badRequests.versionIsNotAvailableForUpgrade(versionStr);
}
try {
// check that the version can be downloaded from the remote repository
repo.checkVersionDownloadable(version);
} catch (RemoteRepositoryException e) {
throw APIException.internalServerErrors.getObjectError("remote repository info", e);
}
List<SoftwareVersion> newList = new ArrayList<SoftwareVersion>(localAvailableVersions);
newList.add(version);
int versionSize = repo.checkVersionSize(version);
_log.info("The size of the image is:" + versionSize);
initializeDownloadProgress(versionStr, versionSize);
try {
_coordinator.setTargetInfo(new RepositoryInfo(currentVersion, newList));
} catch (Exception e) {
throw APIException.internalServerErrors.setObjectToError("target versions", "coordinator", e);
}
auditUpgrade(OperationTypeEnum.INSTALL_IMAGE, AuditLogManager.AUDITLOG_SUCCESS, null, versionStr);
ClusterInfo clusterInfo = _coordinator.getClusterInfo();
if (clusterInfo == null) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster info");
}
return toClusterResponse(clusterInfo);
}
use of com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException in project coprhd-controller by CoprHD.
the class UpgradeService method setTargetVersion.
/**
* Upgrade target version. Refer to product documentation for valid upgrade paths.
*
* @brief Update the target version of the build
* @param version The new version number
* @prereq Target version should be installed and cluster state should be STABLE
* @return Cluster state information.
* @throws IOException
*/
@PUT
@Path("target-version/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response setTargetVersion(@QueryParam("version") String version, @QueryParam("force") String forceUpgrade) throws IOException {
SoftwareVersion targetVersion = null;
try {
targetVersion = new SoftwareVersion(version);
} catch (InvalidSoftwareVersionException e) {
throw APIException.badRequests.parameterIsNotValid("version");
}
// validate
if (!_coordinator.isClusterUpgradable()) {
throw APIException.serviceUnavailable.clusterStateNotStable();
}
if (!_coordinator.isAllDatabaseServiceUp()) {
throw APIException.serviceUnavailable.databaseServiceNotAllUp();
}
// check if all DR sites are in stable or paused status
checkClusterState(true);
List<SoftwareVersion> available = null;
try {
available = _coordinator.getVersions(_coordinator.getMySvcId());
} catch (CoordinatorClientException e) {
throw APIException.internalServerErrors.getObjectFromError("available versions", "coordinator", e);
}
if (!available.contains(targetVersion)) {
throw APIException.badRequests.versionIsNotAvailableForUpgrade(version);
}
// To Do - add a check for upgradable from current
SoftwareVersion current = null;
try {
current = _coordinator.getRepositoryInfo(_coordinator.getMySvcId()).getCurrentVersion();
} catch (CoordinatorClientException e) {
throw APIException.internalServerErrors.getObjectFromError("current version", "coordinator", e);
}
if (!current.isSwitchableTo(targetVersion)) {
throw APIException.badRequests.versionIsNotUpgradable(targetVersion.toString(), current.toString());
}
// Check if allowed from upgrade voter and force option can veto
if (FORCE.equals(forceUpgrade)) {
_log.info("Force option supplied, skipping all geo/dr pre-checks");
} else {
for (UpgradeVoter voter : _upgradeVoters) {
voter.isOKForUpgrade(current.toString(), version);
}
}
try {
_coordinator.setTargetInfo(new RepositoryInfo(targetVersion, _coordinator.getTargetInfo(RepositoryInfo.class).getVersions()));
} catch (Exception e) {
throw APIException.internalServerErrors.setObjectToError("target version", "coordinator", e);
}
_log.info("target version changed successfully. new target {}", targetVersion);
auditUpgrade(OperationTypeEnum.UPDATE_VERSION, AuditLogManager.AUDITLOG_SUCCESS, null, targetVersion.toString(), FORCE.equals(forceUpgrade));
ClusterInfo clusterInfo = _coordinator.getClusterInfo();
if (clusterInfo == null) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster info");
}
return toClusterResponse(clusterInfo);
}
use of com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException in project coprhd-controller by CoprHD.
the class UpgradeService method removeImage.
/**
* Remove an image. Image can be removed only if the number of installed images are
* greater than MAX_SOFTWARE_VERSIONS
*
* @brief Remove an image
* @param versionStr Version to be removed
* @param forceRemove If force=1, image will be removed even if the maximum number of versions installed are less than
* MAX_SOFTWARE_VERSIONS
* @prereq Image should be installed and cluster state should be STABLE
* @return Cluster state information
* @throws IOException
*/
@POST
@Path("image/remove/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response removeImage(@QueryParam("version") String versionStr, @QueryParam("force") String forceRemove) throws IOException {
_log.info("removeImage({})", versionStr);
final SoftwareVersion version;
try {
version = new SoftwareVersion(versionStr);
} catch (InvalidSoftwareVersionException e) {
throw APIException.badRequests.parameterIsNotValid("version");
}
RepositoryInfo targetInfo = null;
try {
targetInfo = _coordinator.getTargetInfo(RepositoryInfo.class);
} catch (Exception e) {
throw APIException.internalServerErrors.getObjectFromError("target repository info", "coordinator", e);
}
final SyncInfo remoteSyncInfo = SyncInfoBuilder.removableVersions(targetInfo, FORCE.equals(forceRemove));
if (remoteSyncInfo.isEmpty() || remoteSyncInfo.getToRemove() == null || !remoteSyncInfo.getToRemove().contains(version)) {
throw APIException.badRequests.versionIsNotRemovable(versionStr);
}
List<SoftwareVersion> newList = new ArrayList<SoftwareVersion>(targetInfo.getVersions());
newList.remove(version);
try {
_coordinator.setTargetInfo(new RepositoryInfo(targetInfo.getCurrentVersion(), newList), !FORCE.equals(forceRemove));
} catch (Exception e) {
throw APIException.internalServerErrors.setObjectToError("target versions", "coordinator", e);
}
auditUpgrade(OperationTypeEnum.REMOVE_IMAGE, AuditLogManager.AUDITLOG_SUCCESS, null, versionStr, FORCE.equals(forceRemove));
ClusterInfo clusterInfo = _coordinator.getClusterInfo();
if (clusterInfo == null) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster info");
}
return toClusterResponse(clusterInfo);
}
use of com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException 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.exceptions.InvalidSoftwareVersionException in project coprhd-controller by CoprHD.
the class ConnectVdcTaskOp method isCompatibleVersion.
/**
* Check to be added vdc whether in compatible version
*/
private boolean isCompatibleVersion(VdcPreCheckResponse vdcResp) {
final SoftwareVersion version;
String shortId = vdcInfo.getProperty(GeoServiceJob.VDC_SHORT_ID);
try {
log.info("software version of vdc {} is {}", shortId, vdcResp.getSoftwareVersion());
version = new SoftwareVersion(vdcResp.getSoftwareVersion());
} catch (InvalidSoftwareVersionException e) {
log.error("software version of vdc {} is incorrect", shortId);
return false;
}
SoftwareVersion myVersion = null;
try {
myVersion = dbClient.getCoordinatorClient().getTargetInfo(RepositoryInfo.class).getCurrentVersion();
} catch (Exception e) {
String errMsg = "Not able to get the software version of current vdc";
log.error(errMsg, e);
throw GeoException.fatals.connectVdcPrecheckFail(shortId, errMsg);
}
log.info("Software version of current vdc: {}", myVersion.toString());
if (myVersion.compareTo(version) == 0) {
log.info("software version equals, pass the version check");
} else if (myVersion.compareTo(version) < 0) {
log.info("to be added vdc has larger version");
if (!vdcResp.getCompatible()) {
log.error("vdc to be added has larger version but incompatible with current vdc");
return false;
}
} else {
log.info("to be added vdc has smaller version");
if (!helper.isCompatibleVersion(version)) {
log.error("vdc to be added has smaller version but incompatible with current vdc");
return false;
}
}
return true;
}
Aggregations