use of com.emc.storageos.model.dr.SiteConfigParam 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;
}
use of com.emc.storageos.model.dr.SiteConfigParam in project coprhd-controller by CoprHD.
the class DisasterRecoveryService method resumeStandby.
/**
* Resume data replication for a paused standby site
*
* @param uuid site UUID
* @brief Resume data replication for a paused standby site
* @return updated standby site representation
*/
@POST
@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("/{uuid}/resume")
public SiteRestRep resumeStandby(@PathParam("uuid") String uuid) {
log.info("Begin to resume data sync to standby site identified by uuid: {}", uuid);
Site standby = validateSiteConfig(uuid);
SiteState state = standby.getState();
if (!state.equals(SiteState.STANDBY_PAUSED) && !state.equals(SiteState.ACTIVE_DEGRADED)) {
log.error("site {} is in state {}, should be STANDBY_PAUSED or ACTIVE_DEGRADED", uuid, standby.getState());
throw APIException.badRequests.operationOnlyAllowedOnPausedSite(standby.getName(), standby.getState().toString());
}
SiteNetworkState networkState = drUtil.getSiteNetworkState(uuid);
if (networkState.getNetworkHealth() == NetworkHealth.BROKEN) {
throw APIException.internalServerErrors.siteConnectionBroken(standby.getName(), "Network health state is broken.");
}
try (InternalSiteServiceClient client = createInternalSiteServiceClient(standby)) {
commonPrecheck();
client.setCoordinatorClient(coordinator);
client.setKeyGenerator(apiSignatureGenerator);
client.resumePrecheck();
} catch (APIException e) {
throw e;
} catch (Exception e) {
throw APIException.internalServerErrors.resumeStandbyPrecheckFailed(standby.getName(), e.getMessage());
}
// Do this before tx get started which might write key to zk.
SecretKey secretKey = apiSignatureGenerator.getSignatureKey(SignatureKeyType.INTERVDC_API);
InterProcessLock lock = drUtil.getDROperationLock();
long vdcTargetVersion = DrUtil.newVdcConfigVersion();
try {
coordinator.startTransaction();
for (Site site : drUtil.listStandbySites()) {
if (site.getUuid().equals(uuid)) {
log.error("Re-init the target standby", uuid);
// init the to-be resumed standby site
long dataRevision = vdcTargetVersion;
List<Site> standbySites = drUtil.listStandbySites();
SiteConfigParam configParam = prepareSiteConfigParam(standbySites, ipsecConfig.getPreSharedKey(), uuid, dataRevision, vdcTargetVersion, secretKey);
try (InternalSiteServiceClient internalSiteServiceClient = new InternalSiteServiceClient()) {
internalSiteServiceClient.setCoordinatorClient(coordinator);
internalSiteServiceClient.setServer(site.getVipEndPoint());
internalSiteServiceClient.initStandby(configParam);
}
site.setState(SiteState.STANDBY_RESUMING);
coordinator.persistServiceConfiguration(site.toConfiguration());
drUtil.recordDrOperationStatus(site.getUuid(), InterState.RESUMING_STANDBY);
drUtil.updateVdcTargetVersion(uuid, SiteInfo.DR_OP_CHANGE_DATA_REVISION, vdcTargetVersion, dataRevision);
} else {
drUtil.updateVdcTargetVersion(site.getUuid(), SiteInfo.DR_OP_RESUME_STANDBY, vdcTargetVersion);
}
}
// update the local(active) site last
drUtil.updateVdcTargetVersion(coordinator.getSiteId(), SiteInfo.DR_OP_RESUME_STANDBY, vdcTargetVersion);
coordinator.commitTransaction();
auditDisasterRecoveryOps(OperationTypeEnum.RESUME_STANDBY, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, standby.toBriefString());
return siteMapper.map(standby);
} catch (Exception e) {
log.error("Error resuming site {}", uuid, e);
coordinator.discardTransaction();
auditDisasterRecoveryOps(OperationTypeEnum.RESUME_STANDBY, AuditLogManager.AUDITLOG_FAILURE, null, standby.toBriefString());
InternalServerErrorException resumeStandbyFailedException = APIException.internalServerErrors.resumeStandbyFailed(standby.getName(), e.getMessage());
throw resumeStandbyFailedException;
} finally {
try {
lock.release();
} catch (Exception ignore) {
log.error(String.format("Lock release failed when resuming standby site: %s", uuid));
}
}
}
use of com.emc.storageos.model.dr.SiteConfigParam 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));
}
}
}
Aggregations