Search in sources :

Example 1 with SiteParam

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

the class DisasterRecoveryService method prepareSiteConfigParam.

/**
 * Prepare all sites related info for synchronizing them from master to be added or resumed standby site
 *
 * @param standbySites All standby sites
 * @param ipsecKey The cluster ipsec key
 * @param targetStandbyUUID The uuid of the target standby
 * @param targetStandbyDataRevision The data revision of the target standby
 * @return SiteConfigParam all the sites configuration
 */
private SiteConfigParam prepareSiteConfigParam(List<Site> standbySites, String ipsecKey, String targetStandbyUUID, long targetStandbyDataRevision, long vdcConfigVersion, SecretKey secretKey) {
    log.info("Preparing to sync sites info among to be added/resumed standby site...");
    Site active = drUtil.getActiveSite();
    SiteConfigParam configParam = new SiteConfigParam();
    SiteParam activeSite = new SiteParam();
    siteMapper.map(active, activeSite);
    activeSite.setIpsecKey(ipsecKey);
    log.info("    active site info:{}", activeSite.toString());
    configParam.setActiveSite(activeSite);
    List<SiteParam> standbySitesParam = new ArrayList<>();
    for (Site standby : standbySites) {
        SiteParam standbyParam = new SiteParam();
        siteMapper.map(standby, standbyParam);
        standbyParam.setSecretKey(new String(Base64.encodeBase64(secretKey.getEncoded()), Charset.forName("UTF-8")));
        if (standby.getUuid().equals(targetStandbyUUID)) {
            log.info("Set data revision for site {} to {}", standby.getUuid(), targetStandbyDataRevision);
            standbyParam.setDataRevision(targetStandbyDataRevision);
        }
        standbySitesParam.add(standbyParam);
        log.info("    standby site info:{}", standbyParam.toString());
    }
    configParam.setStandbySites(standbySitesParam);
    configParam.setVdcConfigVersion(vdcConfigVersion);
    // Need set stanby's NTP same as primary, so standby time is consistent with primary after reboot
    // It's because time inconsistency between primary and standby will cause db rebuild issue: COP-17965
    PropertyInfoExt targetPropInfo = coordinator.getTargetInfo(PropertyInfoExt.class);
    String ntpServers = targetPropInfo.getProperty(NTPSERVERS);
    log.info("    active site ntp servers: {}", ntpServers);
    configParam.setNtpServers(ntpServers);
    return configParam;
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) PropertyInfoExt(com.emc.storageos.coordinator.client.model.PropertyInfoExt) ArrayList(java.util.ArrayList) SiteParam(com.emc.storageos.model.dr.SiteParam) SiteConfigParam(com.emc.storageos.model.dr.SiteConfigParam)

Example 2 with SiteParam

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

the class DisasterRecoveryService method initStandby.

/**
 * Initialize a to-be added/resumed target standby
 * a) re-set all the latest site related info (persisted in ZK) in the target standby
 * b) vdc properties would be changed accordingly
 * c) the target standby reboot
 * d) re-set zk/db data during the target standby reboot
 * e) the target standby would connect with active and sync all the latest ZK&DB data.
 *
 * Scenarios:
 * a) For adding standby site scenario (External API), the current site will be demoted from active to standby during the process
 * b) For resuming standby site scenario (Internal API), the current site's original data will be cleaned by setting new data revision.
 * It is now only used for resuming long paused (> 5 days) standby site
 *
 * @param configParam
 * @return
 */
@PUT
@Path("/internal/initstandby")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response initStandby(SiteConfigParam configParam) {
    try {
        SiteParam activeSiteParam = configParam.getActiveSite();
        ipsecConfig.setPreSharedKey(activeSiteParam.getIpsecKey());
        log.info("Clean up all obsolete site configurations");
        String activeSiteId = activeSiteParam.getUuid();
        Set<String> standbySiteIds = new HashSet<>();
        for (SiteParam standby : configParam.getStandbySites()) {
            standbySiteIds.add(standby.getUuid());
        }
        for (Site siteToRemove : drUtil.listSites()) {
            String siteId = siteToRemove.getUuid();
            if (activeSiteId.equals(siteId) || standbySiteIds.contains(siteId)) {
                continue;
            }
            drUtil.removeSite(siteToRemove);
        }
        coordinator.addSite(activeSiteParam.getUuid());
        Site activeSite = new Site();
        siteMapper.map(activeSiteParam, activeSite);
        activeSite.setVdcShortId(drUtil.getLocalVdcShortId());
        coordinator.persistServiceConfiguration(activeSite.toConfiguration());
        Long dataRevision = null;
        // Add other standby sites
        for (SiteParam standby : configParam.getStandbySites()) {
            Site site = new Site();
            siteMapper.map(standby, site);
            site.setVdcShortId(drUtil.getLocalVdcShortId());
            coordinator.persistServiceConfiguration(site.toConfiguration());
            coordinator.addSite(standby.getUuid());
            if (standby.getUuid().equals(coordinator.getSiteId())) {
                dataRevision = standby.getDataRevision();
                log.info("Set data revision to {}", dataRevision);
            }
            log.info("Persist standby site {} to ZK", standby.getVip());
        }
        if (dataRevision == null) {
            throw new IllegalStateException("Illegal request on standby site. No data revision in request");
        }
        String ntpServers = configParam.getNtpServers();
        PropertyInfoExt targetPropInfo = coordinator.getTargetInfo(PropertyInfoExt.class);
        if (ntpServers != null && !ntpServers.equals(targetPropInfo.getProperty(NTPSERVERS))) {
            targetPropInfo.addProperty(NTPSERVERS, ntpServers);
            coordinator.setTargetInfo(targetPropInfo);
            log.info("Set ntp servers to {}", ntpServers);
        }
        drUtil.updateVdcTargetVersion(coordinator.getSiteId(), SiteInfo.DR_OP_CHANGE_DATA_REVISION, configParam.getVdcConfigVersion(), dataRevision);
        return Response.status(Response.Status.ACCEPTED).build();
    } catch (Exception e) {
        log.error("Internal error for updating coordinator on standby", e);
        throw APIException.internalServerErrors.configStandbyFailed(e.getMessage());
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) PropertyInfoExt(com.emc.storageos.coordinator.client.model.PropertyInfoExt) SiteParam(com.emc.storageos.model.dr.SiteParam) 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) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) ZkPath(com.emc.storageos.coordinator.common.impl.ZkPath) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

PropertyInfoExt (com.emc.storageos.coordinator.client.model.PropertyInfoExt)2 Site (com.emc.storageos.coordinator.client.model.Site)2 SiteParam (com.emc.storageos.model.dr.SiteParam)2 ZkPath (com.emc.storageos.coordinator.common.impl.ZkPath)1 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)1 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)1 SiteConfigParam (com.emc.storageos.model.dr.SiteConfigParam)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1