Search in sources :

Example 1 with UpgradeVoter

use of com.emc.storageos.security.upgradevoter.UpgradeVoter 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);
}
Also used : InvalidSoftwareVersionException(com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) UpgradeVoter(com.emc.storageos.security.upgradevoter.UpgradeVoter) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException) 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) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

RepositoryInfo (com.emc.storageos.coordinator.client.model.RepositoryInfo)1 SoftwareVersion (com.emc.storageos.coordinator.client.model.SoftwareVersion)1 InvalidSoftwareVersionException (com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 UpgradeVoter (com.emc.storageos.security.upgradevoter.UpgradeVoter)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 ServiceUnavailableException (com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException)1 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)1 LocalRepositoryException (com.emc.storageos.systemservices.exceptions.LocalRepositoryException)1 RemoteRepositoryException (com.emc.storageos.systemservices.exceptions.RemoteRepositoryException)1 ClusterInfo (com.emc.vipr.model.sys.ClusterInfo)1 IOException (java.io.IOException)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1