Search in sources :

Example 11 with ClusterInfo

use of com.emc.vipr.model.sys.ClusterInfo 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)

Example 12 with ClusterInfo

use of com.emc.vipr.model.sys.ClusterInfo in project coprhd-controller by CoprHD.

the class CoordinatorClientExt method isActiveSiteStable.

public boolean isActiveSiteStable(Site activeSite) {
    // check if cluster state is stable
    String vip = activeSite.getVipEndPoint();
    int port = _svc.getEndpoint().getPort();
    String baseNodeURL = String.format(SysClientFactory.BASE_URL_FORMAT, vip, port);
    try {
        SysClient client = SysClientFactory.getSysClient(URI.create(baseNodeURL), CHECK_ACTIVE_SITE_STABLE_READ_TIMEOUT_MS, CHECK_ACTIVE_SITE_STABLE_CONNECT_TIMEOUT_MS);
        ClusterInfo clusterInfo = client.get(URI.create(URI_INTERNAL_GET_CLUSTER_INFO), ClusterInfo.class, null);
        _log.info("Get cluster info from active site {}", clusterInfo.getCurrentState());
        if (ClusterState.STABLE.equals(ClusterState.valueOf(clusterInfo.getCurrentState()))) {
            return true;
        }
    } catch (Exception ex) {
        _log.warn("Encounter error when call Sys API on active site{} ", ex.toString());
    }
    return false;
}
Also used : ClusterInfoMapper.toClusterInfo(com.emc.storageos.systemservices.mapper.ClusterInfoMapper.toClusterInfo) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) SysClient(com.emc.storageos.systemservices.impl.client.SysClientFactory.SysClient) 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)

Example 13 with ClusterInfo

use of com.emc.vipr.model.sys.ClusterInfo in project coprhd-controller by CoprHD.

the class ClusterInfoMapper method toClusterInfo.

public static ClusterInfo toClusterInfo(final ClusterState controlNodesState, final Map<Service, RepositoryInfo> controlNodesInfo, final Map<Service, ConfigVersion> controlNodesConfigVersions, final RepositoryInfo targetRepository, final PropertyInfoExt targetProperty) {
    ClusterInfo toClusterInfo = new ClusterInfo();
    toClusterInfo.setCurrentState((controlNodesState != ClusterState.STABLE) ? controlNodesState.toString() : ClusterState.STABLE.toString());
    if (!controlNodesInfo.isEmpty()) {
        toClusterInfo.setControlNodes(new HashMap<String, NodeState>());
        for (Map.Entry<Service, RepositoryInfo> entry : controlNodesInfo.entrySet()) {
            addControlNodeInfo(toClusterInfo, entry.getKey().getNodeId(), entry.getValue(), controlNodesConfigVersions != null ? controlNodesConfigVersions.get(entry.getKey()) : null);
        }
    }
    if (targetRepository != null) {
        addTargetInfo(toClusterInfo, targetRepository, targetProperty);
    }
    return toClusterInfo;
}
Also used : ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) NodeState(com.emc.vipr.model.sys.ClusterInfo.NodeState) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) Service(com.emc.storageos.coordinator.common.Service) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with ClusterInfo

use of com.emc.vipr.model.sys.ClusterInfo in project coprhd-controller by CoprHD.

the class ClusterInfoMapper method toClusterInfoWithSelfLink.

public static ClusterInfo toClusterInfoWithSelfLink(ClusterInfo from) {
    ClusterInfo copyTo = new ClusterInfo();
    copyTo.setCurrentState(from.getCurrentState());
    copyTo.setSelfLink(new RestLinkRep());
    copyTo.getSelfLink().setLinkName("self");
    try {
        copyTo.getSelfLink().setLinkRef(new URI(ClusterInfo.CLUSTER_URI));
    } catch (URISyntaxException e) {
        throw APIException.badRequests.parameterIsNotValidURI(ClusterInfo.CLUSTER_URI);
    }
    return copyTo;
}
Also used : ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) RestLinkRep(com.emc.storageos.model.RestLinkRep) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 15 with ClusterInfo

use of com.emc.vipr.model.sys.ClusterInfo 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

ClusterInfo (com.emc.vipr.model.sys.ClusterInfo)24 RepositoryInfo (com.emc.storageos.coordinator.client.model.RepositoryInfo)7 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)7 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)7 IOException (java.io.IOException)7 Path (javax.ws.rs.Path)7 SoftwareVersion (com.emc.storageos.coordinator.client.model.SoftwareVersion)5 InvalidSoftwareVersionException (com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException)5 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5 ServiceUnavailableException (com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException)5 LocalRepositoryException (com.emc.storageos.systemservices.exceptions.LocalRepositoryException)5 RemoteRepositoryException (com.emc.storageos.systemservices.exceptions.RemoteRepositoryException)5 ArrayList (java.util.ArrayList)4 POST (javax.ws.rs.POST)4 ViPRSystemClient (com.emc.vipr.client.ViPRSystemClient)3 RecoveryStatus (com.emc.vipr.model.sys.recovery.RecoveryStatus)3 Map (java.util.Map)3 Produces (javax.ws.rs.Produces)3 Service (com.emc.storageos.coordinator.common.Service)2 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)2