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));
}
}
}
Aggregations