Search in sources :

Example 6 with Site

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;
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) SiteDetailRestRep(com.emc.storageos.model.dr.SiteDetailRestRep) Date(java.util.Date) 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) Path(javax.ws.rs.Path) ZkPath(com.emc.storageos.coordinator.common.impl.ZkPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with Site

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));
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SiteState(com.emc.storageos.coordinator.client.model.SiteState) ArrayList(java.util.ArrayList) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) 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) Path(javax.ws.rs.Path) ZkPath(com.emc.storageos.coordinator.common.impl.ZkPath) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with Site

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);
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteConfigRestRep(com.emc.storageos.model.dr.SiteConfigRestRep)

Example 9 with Site

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));
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SecretKey(javax.crypto.SecretKey) Configuration(com.emc.storageos.coordinator.common.Configuration) DistributedBarrier(org.apache.curator.framework.recipes.barriers.DistributedBarrier) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) InternalApiSignatureKeyGenerator(com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator) Test(org.junit.Test)

Example 10 with Site

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);
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Configuration(com.emc.storageos.coordinator.common.Configuration) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Site (com.emc.storageos.coordinator.client.model.Site)79 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)21 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)21 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)20 UnknownHostException (java.net.UnknownHostException)18 Produces (javax.ws.rs.Produces)17 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)16 Path (javax.ws.rs.Path)15 ZkPath (com.emc.storageos.coordinator.common.impl.ZkPath)14 ArrayList (java.util.ArrayList)14 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)11 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)11 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)11 SiteInfo (com.emc.storageos.coordinator.client.model.SiteInfo)10 POST (javax.ws.rs.POST)10 SiteState (com.emc.storageos.coordinator.client.model.SiteState)9 Configuration (com.emc.storageos.coordinator.common.Configuration)8 VirtualDataCenter (com.emc.storageos.db.client.model.VirtualDataCenter)8 Consumes (javax.ws.rs.Consumes)8 ClusterInfo (com.emc.vipr.model.sys.ClusterInfo)6