Search in sources :

Example 6 with SiteConfigRestRep

use of com.emc.storageos.model.dr.SiteConfigRestRep in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method addStandby.

/**
 * Attach one fresh install site to this active site as standby
 * Or attach a active site for the local standby site when it's first being added.
 *
 * @param param site detail information
 * @brief Add standby site
 * @return site response information
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN }, blockProxies = true)
public SiteRestRep addStandby(SiteAddParam param) {
    log.info("Adding standby site: {}", param.getVip());
    precheckForSiteNumber();
    precheckForGeo();
    List<Site> existingSites = drUtil.listStandbySites();
    // parameter validation and precheck
    validateAddParam(param, existingSites);
    // check the version before using the ViPR client, otherwise there might be compatibility issues.
    precheckStandbyVersion(param);
    ViPRCoreClient viprCoreClient;
    SiteConfigRestRep standbyConfig;
    try {
        viprCoreClient = createViPRCoreClient(param.getVip(), param.getUsername(), param.getPassword());
        standbyConfig = viprCoreClient.site().getStandbyConfig();
    } catch (Exception e) {
        log.error("Unexpected error when retrieving standby config", e);
        throw APIException.internalServerErrors.addStandbyPrecheckFailed("Cannot retrieve config from standby site");
    }
    String siteId = standbyConfig.getUuid();
    precheckForStandbyAdd(standbyConfig, viprCoreClient);
    InterProcessLock lock = drUtil.getDROperationLock();
    Site standbySite = null;
    try {
        standbySite = new Site();
        standbySite.setCreationTime((new Date()).getTime());
        standbySite.setName(param.getName());
        standbySite.setVdcShortId(drUtil.getLocalVdcShortId());
        standbySite.setVip(standbyConfig.getVip());
        standbySite.setVip6(standbyConfig.getVip6());
        standbySite.getHostIPv4AddressMap().putAll(new StringMap(standbyConfig.getHostIPv4AddressMap()));
        standbySite.getHostIPv6AddressMap().putAll(new StringMap(standbyConfig.getHostIPv6AddressMap()));
        standbySite.setNodeCount(standbyConfig.getNodeCount());
        standbySite.setUuid(standbyConfig.getUuid());
        String shortId = generateShortId(drUtil.listSites());
        standbySite.setSiteShortId(shortId);
        standbySite.setDescription(param.getDescription());
        standbySite.setState(SiteState.STANDBY_ADDING);
        if (log.isDebugEnabled()) {
            log.debug(standbySite.toString());
        }
        // Do this before tx get started which might write key to zk.
        SecretKey secretKey = apiSignatureGenerator.getSignatureKey(SignatureKeyType.INTERVDC_API);
        coordinator.startTransaction();
        coordinator.addSite(standbyConfig.getUuid());
        log.info("Persist standby site to ZK {}", shortId);
        // coordinator.setTargetInfo(standbySite);
        coordinator.persistServiceConfiguration(standbySite.toConfiguration());
        drUtil.recordDrOperationStatus(standbySite.getUuid(), InterState.ADDING_STANDBY);
        // wake up syssvc to regenerate configurations
        long vdcConfigVersion = DrUtil.newVdcConfigVersion();
        drUtil.updateVdcTargetVersion(coordinator.getSiteId(), SiteInfo.DR_OP_ADD_STANDBY, vdcConfigVersion);
        for (Site site : existingSites) {
            drUtil.updateVdcTargetVersion(site.getUuid(), SiteInfo.DR_OP_ADD_STANDBY, vdcConfigVersion);
        }
        // sync site related info with to be added standby site
        long dataRevision = vdcConfigVersion;
        List<Site> allStandbySites = new ArrayList<>();
        allStandbySites.add(standbySite);
        allStandbySites.addAll(existingSites);
        SiteConfigParam configParam = prepareSiteConfigParam(allStandbySites, ipsecConfig.getPreSharedKey(), standbyConfig.getUuid(), dataRevision, vdcConfigVersion, secretKey);
        viprCoreClient.site().syncSite(standbyConfig.getUuid(), configParam);
        drUtil.updateVdcTargetVersion(siteId, SiteInfo.DR_OP_CHANGE_DATA_REVISION, vdcConfigVersion, dataRevision);
        coordinator.commitTransaction();
        auditDisasterRecoveryOps(OperationTypeEnum.ADD_STANDBY, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, standbySite.toBriefString());
        return siteMapper.map(standbySite);
    } catch (Exception e) {
        log.error("Internal error for updating coordinator on standby", e);
        coordinator.discardTransaction();
        auditDisasterRecoveryOps(OperationTypeEnum.ADD_STANDBY, AuditLogManager.AUDITLOG_FAILURE, null, standbySite.toBriefString());
        InternalServerErrorException addStandbyFailedException = APIException.internalServerErrors.addStandbyFailed(e.getMessage());
        throw addStandbyFailedException;
    } finally {
        try {
            lock.release();
        } catch (Exception ignore) {
            log.error(String.format("Lock release failed when adding standby %s", siteId));
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) StringMap(com.emc.storageos.db.client.model.StringMap) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) ArrayList(java.util.ArrayList) SiteConfigParam(com.emc.storageos.model.dr.SiteConfigParam) 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) Date(java.util.Date) SecretKey(javax.crypto.SecretKey) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) SiteConfigRestRep(com.emc.storageos.model.dr.SiteConfigRestRep) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

SiteConfigRestRep (com.emc.storageos.model.dr.SiteConfigRestRep)6 Site (com.emc.storageos.coordinator.client.model.Site)5 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)3 Matchers.anyString (org.mockito.Matchers.anyString)3 RepositoryInfo (com.emc.storageos.coordinator.client.model.RepositoryInfo)2 Configuration (com.emc.storageos.coordinator.common.Configuration)2 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)2 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)2 DRNatCheckParam (com.emc.storageos.model.dr.DRNatCheckParam)2 SiteConfigParam (com.emc.storageos.model.dr.SiteConfigParam)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)2 SiteMapper (com.emc.storageos.api.mapper.SiteMapper)1 ProductName (com.emc.storageos.coordinator.client.model.ProductName)1 PropertyInfoExt (com.emc.storageos.coordinator.client.model.PropertyInfoExt)1