use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.
the class DisasterRecoveryService method getSiteDetails.
/**
* Query the site details, such as transition timings, for specific standby site
*
* @param uuid site UUID
* @brief Get site details
* @return SiteActionsTime with detail information
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
@Path("/{uuid}/details")
public SiteDetailRestRep getSiteDetails(@PathParam("uuid") String uuid) {
log.info("Begin to get site paused time by uuid {}", uuid);
SiteDetailRestRep standbyDetails = new SiteDetailRestRep();
try {
Site standby = drUtil.getSiteFromLocalVdc(uuid);
standbyDetails.setCreationTime(new Date(standby.getCreationTime()));
Double latency = drUtil.getSiteNetworkState(uuid).getNetworkLatencyInMs();
standbyDetails.setNetworkLatencyInMs(latency);
Date lastSyncTime = drUtil.getLastSyncTime(standby);
if (lastSyncTime != null) {
standbyDetails.setLastSyncTime(lastSyncTime);
}
standbyDetails.setDataSynced(isDataSynced(standby));
ClusterInfo.ClusterState clusterState = coordinator.getControlNodesState(standby.getUuid());
if (clusterState != null) {
standbyDetails.setClusterState(clusterState.toString());
} else {
standbyDetails.setClusterState(ClusterInfo.ClusterState.UNKNOWN.toString());
}
standbyDetails.setSiteState(standby.getState().toString());
} catch (CoordinatorException e) {
log.error("Can't find site {} from ZK", uuid);
throw APIException.badRequests.siteIdNotFound();
} catch (Exception e) {
log.error("Find find site from ZK for UUID {} : {}" + uuid, e);
}
return standbyDetails;
}
use of com.emc.storageos.coordinator.client.model.Site 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));
}
}
}
use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method testGetStandbyConfig.
public void testGetStandbyConfig() {
doReturn(secretKey).when(apiSignatureGeneratorMock).getSignatureKey(SignatureKeyType.INTERVDC_API);
Site site = new Site();
site.setState(SiteState.ACTIVE);
doReturn(standbySite1.toConfiguration()).when(coordinator).queryConfiguration(String.format("%s/vdc1", Site.CONFIG_KIND), coordinator.getSiteId());
SiteConfigRestRep response = drService.getStandbyConfig();
compareSiteResponse(response, standbyConfig);
}
use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method testPlannedFailover_noError.
@Test
public void testPlannedFailover_noError() throws Exception {
List<Site> sites = new ArrayList<>();
sites.add(primarySite);
sites.add(standbySite2);
SecretKey keyMock = mock(SecretKey.class);
InternalApiSignatureKeyGenerator apiSignatureGeneratorMock = mock(InternalApiSignatureKeyGenerator.class);
doReturn("SecreteKey".getBytes()).when(keyMock).getEncoded();
doReturn(keyMock).when(apiSignatureGeneratorMock).getSignatureKey(SignatureKeyType.INTERVDC_API);
doReturn(sites).when(drUtil).listSites();
doReturn(primarySite).when(drUtil).getActiveSite();
doReturn(true).when(drUtil).isSiteUp(standbySite2.getUuid());
doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState(standbySite2.getUuid());
doReturn(mock(DistributedBarrier.class)).when(coordinator).getDistributedBarrier(any(String.class));
doNothing().when(drService).precheckForSwitchover(standbySite2.getUuid());
drService.setApiSignatureGenerator(apiSignatureGeneratorMock);
drService.doSwitchover(standbySite2.getUuid());
verify(coordinator, times(1)).persistServiceConfiguration(any(Configuration.class));
}
use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method testPrecheckForPlannedFailover.
@Test
public void testPrecheckForPlannedFailover() {
String standbyUUID = "a918ebd4-bbf4-378b-8034-b03423f9edfd";
// test for invalid uuid
try {
APIException e = APIException.internalServerErrors.switchoverPrecheckFailed(standby.getUuid(), "Standby uuid is not valid, can't find in ZK");
doThrow(e).when(drUtil).getSiteFromLocalVdc(standbyUUID);
drService.precheckForSwitchover(standbyUUID);
fail("should throw exception when met invalid standby uuid");
} catch (InternalServerErrorException e) {
assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
}
Site site = new Site();
site.setUuid(standbyUUID);
Configuration config = site.toConfiguration();
// test for failover to primary
try {
// Mock a standby in coordinator, so it would pass invalid standby checking, go to next check
doReturn(config).when(coordinator).queryConfiguration(String.format("%s/vdc1", Site.CONFIG_KIND), standbyUUID);
drService.precheckForSwitchover(standbyUUID);
fail("should throw exception when trying to failover to a primary site");
} catch (InternalServerErrorException e) {
assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
}
// test for primary unstable case
try {
// Mock a primary site with different uuid with to-be-failover standby, so go to next check
doReturn(false).when(drService).isClusterStable();
drService.precheckForSwitchover(standbyUUID);
fail("should throw exception when primary is not stable");
} catch (InternalServerErrorException e) {
assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
}
// test for standby unstable case
try {
// Mock a stable status for primary, so go to next check
doReturn(true).when(drService).isClusterStable();
doReturn(ClusterInfo.ClusterState.DEGRADED).when(coordinator).getControlNodesState(eq(standbyUUID));
drService.precheckForSwitchover(standbyUUID);
fail("should throw exception when site to failover to is not stable");
} catch (InternalServerErrorException e) {
assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
}
// test for standby not STANDBY_CYNCED state
try {
// Mock a stable status for standby, so go to next check
doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState(anyString());
// not fully synced
config.setConfig("state", "STANDBY_SYNCING");
doReturn(config).when(coordinator).queryConfiguration(String.format("%s/vdc1", Site.CONFIG_KIND), standbyUUID);
drService.precheckForSwitchover(standbyUUID);
fail("should throw exception when standby site is not fully synced");
} catch (InternalServerErrorException e) {
assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
}
}
Aggregations