Search in sources :

Example 1 with SiteState

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

the class DisasterRecoveryService method pause.

/**
 * Pause data replication to multiple standby sites.
 *
 * @param idList site uuid list to be removed
 * @brief Pause data replication to multiple standby sites.
 * @return Response
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN }, blockProxies = true)
@Path("/pause")
public Response pause(SiteIdListParam idList) {
    List<String> siteIdList = idList.getIds();
    String siteIdStr = StringUtils.join(siteIdList, ",");
    log.info("Begin to pause standby site from local vdc by uuid: {}", siteIdStr);
    List<Site> toBePausedSites = new ArrayList<>();
    List<String> siteNameList = new ArrayList<>();
    for (String siteId : siteIdList) {
        Site site;
        try {
            site = drUtil.getSiteFromLocalVdc(siteId);
        } catch (Exception ex) {
            log.error("Can't load site {} from ZK", siteId);
            throw APIException.badRequests.siteIdNotFound();
        }
        SiteState state = site.getState();
        if (state.equals(SiteState.ACTIVE)) {
            log.error("Unable to pause this site {}. It is active", siteId);
            throw APIException.badRequests.operationNotAllowedOnActiveSite();
        }
        if (!state.equals(SiteState.STANDBY_SYNCED)) {
            log.error("Unable to pause this site {}. It is in state {}", siteId, state);
            throw APIException.badRequests.operationOnlyAllowedOnSyncedSite(site.getName(), state.toString());
        }
        toBePausedSites.add(site);
        siteNameList.add(site.getName());
    }
    // This String is only used to output human readable message to user when Exception is thrown
    String siteNameStr = StringUtils.join(siteNameList, ',');
    precheckForPause(siteNameStr);
    try {
        // the site(s) to be paused must be checked as well
        commonPrecheck();
    } catch (APIException e) {
        throw e;
    } catch (Exception e) {
        throw APIException.internalServerErrors.pauseStandbyPrecheckFailed(siteNameStr, e.getMessage());
    }
    InterProcessLock lock = drUtil.getDROperationLock();
    // any error is not retry-able beyond this point.
    List<String> sitesString = new ArrayList<>();
    try {
        log.info("Pausing sites");
        long vdcTargetVersion = DrUtil.newVdcConfigVersion();
        coordinator.startTransaction();
        for (Site site : toBePausedSites) {
            site.setState(SiteState.STANDBY_PAUSING);
            site.setLastStateUpdateTime(System.currentTimeMillis());
            coordinator.persistServiceConfiguration(site.toConfiguration());
            drUtil.recordDrOperationStatus(site.getUuid(), InterState.PAUSING_STANDBY);
            sitesString.add(site.toBriefString());
            // notify the to-be-paused sites before others.
            drUtil.updateVdcTargetVersion(site.getUuid(), SiteInfo.DR_OP_PAUSE_STANDBY, vdcTargetVersion);
        }
        log.info("Notify all sites for reconfig");
        for (Site site : drUtil.listSites()) {
            if (toBePausedSites.contains(site)) {
                // already notified
                continue;
            }
            drUtil.updateVdcTargetVersion(site.getUuid(), SiteInfo.DR_OP_PAUSE_STANDBY, vdcTargetVersion);
        }
        coordinator.commitTransaction();
        auditDisasterRecoveryOps(OperationTypeEnum.PAUSE_STANDBY, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, StringUtils.join(sitesString, ','));
        return Response.status(Response.Status.ACCEPTED).build();
    } catch (Exception e) {
        log.error("Failed to pause site {}", siteIdStr, e);
        coordinator.discardTransaction();
        auditDisasterRecoveryOps(OperationTypeEnum.PAUSE_STANDBY, AuditLogManager.AUDITLOG_FAILURE, null, StringUtils.join(sitesString, ','));
        throw APIException.internalServerErrors.pauseStandbyFailed(siteNameStr, e.getMessage());
    } finally {
        try {
            lock.release();
        } catch (Exception ignore) {
            log.error(String.format("Lock release failed when pausing standby site: %s", siteIdStr));
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SiteState(com.emc.storageos.coordinator.client.model.SiteState) ArrayList(java.util.ArrayList) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) UnknownHostException(java.net.UnknownHostException) Path(javax.ws.rs.Path) ZkPath(com.emc.storageos.coordinator.common.impl.ZkPath) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with SiteState

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

the class VirtualDataCenterService method setKeyCertificatePair.

/**
 * Rotate the VIPR key and certificate chain.
 *
 * @param rotateKeyAndCertParam
 * @return the new certificate chain being used by ViPR
 * @brief Rotate the VIPR key and certificate chain to a new system self-signed or a specified input.
 */
@Path("/keystore")
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN }, blockProxies = true)
public CertificateChain setKeyCertificatePair(RotateKeyAndCertParam rotateKeyAndCertParam) {
    if (!coordinator.isClusterUpgradable()) {
        throw SecurityException.retryables.updatingKeystoreWhileClusterIsUnstable();
    }
    if (!drUtil.isActiveSite()) {
        SiteState state = drUtil.getLocalSite().getState();
        if (state == SiteState.STANDBY_PAUSING || state == SiteState.STANDBY_PAUSED || state == SiteState.STANDBY_RESUMING) {
            throw SecurityException.retryables.failToUpdateKeyStoreDueToStandbyPause();
        }
    }
    Boolean selfsigned = rotateKeyAndCertParam.getSystemSelfSigned();
    byte[] key = null;
    Certificate[] chain = null;
    RSAPrivateKey rsaPrivateKey = null;
    try {
        if (selfsigned != null && selfsigned) {
            KeyCertificateEntry pair = getGenerator().generateKeyCertificatePair();
            // key is needed to clear
            key = pair.getKey();
            chain = pair.getCertificateChain();
        } else {
            KeyAndCertificateChain newKey = rotateKeyAndCertParam.getKeyCertChain();
            if (newKey == null || StringUtils.isBlank(newKey.getCertificateChain()) || StringUtils.isBlank(newKey.getPrivateKey())) {
                throw APIException.badRequests.requiredParameterMissingOrEmpty("key_and_certificate");
            }
            try {
                chain = KeyCertificatePairGenerator.getCertificateChainFromString(newKey.getCertificateChain());
                if (ArrayUtils.isEmpty(chain)) {
                    throw APIException.badRequests.failedToLoadCertificateFromString(newKey.getCertificateChain());
                }
                X509Certificate cert = (X509Certificate) chain[0];
                cert.checkValidity();
                key = SecurityUtil.loadPrivateKeyFromPEMString(newKey.getPrivateKey());
                rsaPrivateKey = (RSAPrivateKey) KeyCertificatePairGenerator.loadPrivateKeyFromBytes(key);
                int keyLength = rsaPrivateKey.getModulus().bitLength();
                if (keyLength < KeyCertificateAlgorithmValuesHolder.FIPS_MINIMAL_KEY_SIZE) {
                    throw APIException.badRequests.invalidParameterBelowMinimum("private_key", keyLength, KeyCertificateAlgorithmValuesHolder.FIPS_MINIMAL_KEY_SIZE, "bits");
                }
                KeyCertificatePairGenerator.validateKeyAndCertPairing(rsaPrivateKey, chain);
                Certificate prevCert = null;
                try {
                    prevCert = getKeyStore().getCertificate(KeystoreEngine.ViPR_KEY_AND_CERTIFICATE_ALIAS);
                    if (cert.equals(prevCert)) {
                        throw APIException.badRequests.newCertificateMustBeSpecified();
                    }
                } catch (KeyStoreException e) {
                    _log.error("failed to get previous certificate", e);
                }
                selfsigned = Boolean.FALSE;
            } catch (CertificateExpiredException | CertificateNotYetValidException e) {
                throw APIException.badRequests.invalidField("key_and_certificate", chain[0].toString());
            } catch (CertificateException e) {
                throw APIException.badRequests.failedToLoadCertificateFromString(newKey.getCertificateChain(), e);
            }
        }
        Boolean selfSignedPrevious = KeyStoreUtil.isSelfGeneratedCertificate(coordConfigStoringHelper);
        // This has to be done before the set keys entry call
        KeyStoreUtil.setSelfGeneratedCertificate(coordConfigStoringHelper, selfsigned);
        try {
            getKeyStore().setKeyEntry(KeystoreEngine.ViPR_KEY_AND_CERTIFICATE_ALIAS, key, chain);
        } catch (KeyStoreException e) {
            _log.error("failed to rotate key and certificate chain.");
            KeyStoreUtil.setSelfGeneratedCertificate(coordConfigStoringHelper, selfSignedPrevious);
            throw SecurityException.fatals.failedToUpdateKeyCertificateEntry(e);
        }
        if (!certificateVersionHelper.updateCertificateVersion()) {
            _log.error("failed to update version for new key and certificate chain.");
            throw SecurityException.fatals.failedToUpdateKeyCertificateEntry();
        }
        return getCertificateChain();
    } finally {
        if (key != null) {
            // SensitiveData.clear(key);
            SecurityUtil.clearSensitiveData(key);
        }
        if (rsaPrivateKey != null) {
            // SensitiveData.clear(rsaPrivateKey);
            SecurityUtil.clearSensitiveData(rsaPrivateKey);
        }
    }
}
Also used : KeyAndCertificateChain(com.emc.vipr.model.keystore.KeyAndCertificateChain) KeyStoreException(java.security.KeyStoreException) KeyCertificateEntry(com.emc.storageos.security.keystore.impl.KeyCertificateEntry) SiteState(com.emc.storageos.coordinator.client.model.SiteState) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with SiteState

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

the class SiteMapper method mapWithNetwork.

public SiteRestRep mapWithNetwork(Site from, DrUtil drUtil) {
    if (from == null) {
        return null;
    }
    SiteRestRep to = new SiteRestRep();
    map(from, to);
    NetworkHealth networkHealth = drUtil.getSiteNetworkState(from.getUuid()).getNetworkHealth();
    SiteState state = from.getState();
    // Skip network health state amid ADDING/RESUMING
    if (networkHealth != null && SiteState.STANDBY_ADDING != state && SiteState.STANDBY_RESUMING != state) {
        to.setNetworkHealth(networkHealth.toString());
    }
    // check if syssvc are up
    boolean runningState = drUtil.isSiteUp(from.getUuid());
    if (runningState && !from.getState().equals(SiteState.ACTIVE)) {
        // check if dbsvc are up
        SiteMonitorResult monitorResult = drUtil.getCoordinator().getTargetInfo(from.getUuid(), SiteMonitorResult.class);
        if (monitorResult != null && monitorResult.getDbQuorumLostSince() > 0) {
            runningState = false;
        }
    }
    to.setRunningState(runningState);
    return to;
}
Also used : SiteRestRep(com.emc.storageos.model.dr.SiteRestRep) SiteState(com.emc.storageos.coordinator.client.model.SiteState) SiteMonitorResult(com.emc.storageos.coordinator.client.model.SiteMonitorResult) NetworkHealth(com.emc.storageos.coordinator.client.model.SiteNetworkState.NetworkHealth)

Example 4 with SiteState

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

the class SchemaUtil method checkDataRevision.

public void checkDataRevision(String localDataRevision) {
    Site currentSite = drUtil.getLocalSite();
    SiteState siteState = currentSite.getState();
    if (siteState == SiteState.STANDBY_ADDING || siteState == SiteState.STANDBY_RESUMING || siteState == SiteState.STANDBY_SYNCING) {
        SiteInfo targetSiteInfo = _coordinator.getTargetInfo(_coordinator.getSiteId(), SiteInfo.class);
        String targetDataRevision = targetSiteInfo.getTargetDataRevision();
        _log.info("Target data revision {}", targetDataRevision);
        if (localDataRevision.equals(targetDataRevision)) {
            if (siteState != SiteState.STANDBY_SYNCING) {
                _log.info("Change site state to SYNCING and rebuild data from active site");
                currentSite.setLastState(siteState);
                currentSite.setState(SiteState.STANDBY_SYNCING);
                _coordinator.persistServiceConfiguration(currentSite.toConfiguration());
            }
            dbRebuildRunnable.run();
        } else {
            _log.info("Incompatible data revision - local {} target {}. Skip data rebuild", localDataRevision, targetDataRevision);
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteInfo(com.emc.storageos.coordinator.client.model.SiteInfo) SiteState(com.emc.storageos.coordinator.client.model.SiteState)

Example 5 with SiteState

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

the class DrSiteNetworkMonitor method checkPing.

private void checkPing() {
    Site localSite = drUtil.getLocalSite();
    SiteNetworkState localNetworkState = drUtil.getSiteNetworkState(localSite.getUuid());
    if (!NetworkHealth.GOOD.equals(localNetworkState.getNetworkHealth()) || localNetworkState.getNetworkLatencyInMs() != 0) {
        localNetworkState.setNetworkLatencyInMs(0);
        localNetworkState.setNetworkHealth(NetworkHealth.GOOD);
        coordinatorClient.setTargetInfo(localSite.getUuid(), localNetworkState);
    }
    for (Site site : drUtil.listSites()) {
        if (drUtil.isLocalSite(site)) {
            // skip local site
            continue;
        }
        SiteNetworkState siteNetworkState = drUtil.getSiteNetworkState(site.getUuid());
        NetworkHealth previousState = siteNetworkState.getNetworkHealth();
        String host = site.getVipEndPoint();
        double ping = drUtil.testPing(host, SOCKET_TEST_PORT, NETWORK_TIMEOUT);
        // if ping successful get an average, format to 3 decimal places
        if (ping != -1) {
            ping = (ping + drUtil.testPing(host, SOCKET_TEST_PORT, NETWORK_TIMEOUT) + drUtil.testPing(host, SOCKET_TEST_PORT, NETWORK_TIMEOUT)) / 3;
            DecimalFormat df = new DecimalFormat("#.###");
            ping = Double.parseDouble(df.format(ping));
        }
        _log.info("Ping: " + ping);
        siteNetworkState.setNetworkLatencyInMs(ping);
        if (ping > NETWORK_SLOW_THRESHOLD) {
            siteNetworkState.setNetworkHealth(NetworkHealth.SLOW);
            _log.warn("Network for standby {} is slow", site.getName());
            AlertsLogger.getAlertsLogger().warn(String.format("Network for standby %s is Broken:" + "Latency was reported as %f ms", site.getName(), ping));
        } else if (ping < 0) {
            siteNetworkState.setNetworkHealth(NetworkHealth.BROKEN);
            _log.error("Network for standby {} is broken", site.getName());
            AlertsLogger.getAlertsLogger().error(String.format("Network for standby %s is Broken:" + "Latency was reported as %s ms", site.getName(), ping));
        } else {
            siteNetworkState.setNetworkHealth(NetworkHealth.GOOD);
        }
        coordinatorClient.setTargetInfo(site.getUuid(), siteNetworkState);
        if (drUtil.isActiveSite()) {
            SiteState state = site.getState();
            if (SiteState.STANDBY_ADDING == state || SiteState.STANDBY_RESUMING == state) {
                _log.info("Skip mail alert during add-standby or resume-standby for {}", site.getUuid());
                continue;
            }
            if (!NetworkHealth.BROKEN.equals(previousState) && NetworkHealth.BROKEN.equals(siteNetworkState.getNetworkHealth())) {
                // Add to systemevent log
                _alertLog.error(MessageFormat.format("Network connection to site %s has been broken.", site.getName()));
                // send email alert
                mailHandler.sendSiteNetworkBrokenMail(site);
            }
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteState(com.emc.storageos.coordinator.client.model.SiteState) NetworkHealth(com.emc.storageos.coordinator.client.model.SiteNetworkState.NetworkHealth) DecimalFormat(java.text.DecimalFormat) SiteNetworkState(com.emc.storageos.coordinator.client.model.SiteNetworkState)

Aggregations

SiteState (com.emc.storageos.coordinator.client.model.SiteState)13 Site (com.emc.storageos.coordinator.client.model.Site)9 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)3 SiteNetworkState (com.emc.storageos.coordinator.client.model.SiteNetworkState)2 NetworkHealth (com.emc.storageos.coordinator.client.model.SiteNetworkState.NetworkHealth)2 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)2 ZkPath (com.emc.storageos.coordinator.common.impl.ZkPath)2 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)2 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)2 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)2 UnknownHostException (java.net.UnknownHostException)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 InternalSiteServiceClient (com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient)1 MigrationStatus (com.emc.storageos.coordinator.client.model.MigrationStatus)1 SiteError (com.emc.storageos.coordinator.client.model.SiteError)1