Search in sources :

Example 1 with RepositoryInfo

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

the class CoordinatorClientImpl method getDifferentCurrentsCommon.

/**
 * Common method to compare current version with target's current version
 *
 * @param targetGiven
 *            target repository
 * @param infos
 *            nodes' repository
 * @return list of nodes which current version is different from the target's
 */
private List<String> getDifferentCurrentsCommon(final RepositoryInfo targetGiven, final Map<Service, RepositoryInfo> infos) {
    List<String> differentCurrents = new ArrayList<String>();
    final SoftwareVersion targetCurrent = targetGiven.getCurrentVersion();
    for (Map.Entry<Service, RepositoryInfo> entry : infos.entrySet()) {
        if (!targetCurrent.equals(entry.getValue().getCurrentVersion())) {
            differentCurrents.add(entry.getKey().getId());
        }
    }
    return differentCurrents;
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) ArrayList(java.util.ArrayList) Service(com.emc.storageos.coordinator.common.Service) ExecutorService(java.util.concurrent.ExecutorService) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 2 with RepositoryInfo

use of com.emc.storageos.coordinator.client.model.RepositoryInfo 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);
}
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) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) ArrayList(java.util.ArrayList) 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) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with RepositoryInfo

use of com.emc.storageos.coordinator.client.model.RepositoryInfo 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)

Example 4 with RepositoryInfo

use of com.emc.storageos.coordinator.client.model.RepositoryInfo 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);
}
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) ArrayList(java.util.ArrayList) 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) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with RepositoryInfo

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

the class CoordinatorClientExt method getClusterInfo.

public ClusterInfo getClusterInfo(String siteIdParam) {
    try {
        String siteId = siteIdParam == null ? _coordinator.getSiteId() : siteIdParam;
        // get target repository and configVersion
        final RepositoryInfo targetRepository = _coordinator.getTargetInfo(RepositoryInfo.class);
        final PropertyInfoExt targetProperty = _coordinator.getTargetInfo(PropertyInfoExt.class);
        // get control nodes' repository and configVersion info
        final Map<Service, RepositoryInfo> controlNodesInfo = getAllNodeInfos(RepositoryInfo.class, CONTROL_NODE_SYSSVC_ID_PATTERN, siteId);
        final Map<Service, ConfigVersion> controlNodesConfigVersions = getAllNodeInfos(ConfigVersion.class, CONTROL_NODE_SYSSVC_ID_PATTERN, siteId);
        ClusterInfo.ClusterState controlNodesState = _coordinator.getControlNodesState(siteId);
        // rotating ipsec key. We should report upgrade in progress on UI
        if (backCompatPreYoda && ClusterInfo.ClusterState.STABLE.equals(controlNodesState)) {
            if (!drUtil.isMultivdc()) {
                _log.info("Back compat flag for preyoda is true. ");
                controlNodesState = ClusterInfo.ClusterState.UPDATING;
            }
        }
        // cluster state is determined both by control nodes' state and extra nodes
        return toClusterInfo(controlNodesState, controlNodesInfo, controlNodesConfigVersions, targetRepository, targetProperty);
    } catch (Exception e) {
        _log.info("Fail to get the cluster information ", e);
        return null;
    }
}
Also used : ClusterInfoMapper.toClusterInfo(com.emc.storageos.systemservices.mapper.ClusterInfoMapper.toClusterInfo) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) PropertyInfoExt(com.emc.storageos.coordinator.client.model.PropertyInfoExt) ConfigVersion(com.emc.storageos.coordinator.client.model.ConfigVersion) Service(com.emc.storageos.coordinator.common.Service) ClusterState(com.emc.vipr.model.sys.ClusterInfo.ClusterState) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) SyssvcException(com.emc.storageos.systemservices.exceptions.SyssvcException) InvalidLockOwnerException(com.emc.storageos.systemservices.exceptions.InvalidLockOwnerException) IOException(java.io.IOException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException)

Aggregations

RepositoryInfo (com.emc.storageos.coordinator.client.model.RepositoryInfo)17 SoftwareVersion (com.emc.storageos.coordinator.client.model.SoftwareVersion)10 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)6 ClusterInfo (com.emc.vipr.model.sys.ClusterInfo)6 IOException (java.io.IOException)6 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)5 Service (com.emc.storageos.coordinator.common.Service)4 InvalidSoftwareVersionException (com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException)4 ServiceUnavailableException (com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException)4 LocalRepositoryException (com.emc.storageos.systemservices.exceptions.LocalRepositoryException)4 RemoteRepositoryException (com.emc.storageos.systemservices.exceptions.RemoteRepositoryException)4 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 Test (org.junit.Test)3 ConfigVersion (com.emc.storageos.coordinator.client.model.ConfigVersion)2 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)2 PropertyInfoRestRep (com.emc.storageos.model.property.PropertyInfoRestRep)2 LocalRepository (com.emc.storageos.systemservices.impl.upgrade.LocalRepository)2