Search in sources :

Example 1 with InternalSiteServiceClient

use of com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method testResumeStandby.

@Test
public void testResumeStandby() {
    try {
        drService.resumeStandby(primarySite.getUuid());
    } catch (APIException e) {
        assertEquals(e.getServiceCode(), ServiceCode.API_BAD_REQUEST);
    }
    try {
        drService.resumeStandby(NONEXISTENT_ID);
    } catch (APIException e) {
        assertEquals(e.getServiceCode(), ServiceCode.API_PARAMETER_INVALID);
    }
    doNothing().when(coordinator).persistServiceConfiguration(any(Configuration.class));
    doReturn(null).when(coordinator).getTargetInfo(any(String.class), eq(SiteInfo.class));
    doNothing().when(coordinator).setTargetInfo(any(String.class), any(SiteInfo.class));
    InternalSiteServiceClient internalSiteClient = mock(InternalSiteServiceClient.class);
    doReturn(internalSiteClient).when(drService).createInternalSiteServiceClient(any(Site.class));
    try {
        SiteRestRep response = drService.resumeStandby(standbySite1.getUuid());
        assertEquals(SiteState.STANDBY_PAUSED.toString(), response.getState());
    } catch (Exception e) {
        fail();
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteInfo(com.emc.storageos.coordinator.client.model.SiteInfo) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SiteRestRep(com.emc.storageos.model.dr.SiteRestRep) Configuration(com.emc.storageos.coordinator.common.Configuration) InternalSiteServiceClient(com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient) Matchers.anyString(org.mockito.Matchers.anyString) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) Test(org.junit.Test)

Example 2 with InternalSiteServiceClient

use of com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method isLocalSiteRemoved.

/**
 *  Check if Local Site Removed
 *
 * @brief Check if local site is removed
 * @return result that indicates whether local site is removed
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/islocalsiteremoved")
public SiteRemoved isLocalSiteRemoved() {
    SiteRemoved response = new SiteRemoved();
    Site localSite = drUtil.getLocalSite();
    if (SiteState.ACTIVE == localSite.getState()) {
        return response;
    }
    for (Site remoteSite : drUtil.listSites()) {
        if (remoteSite.getUuid().equals(localSite.getUuid())) {
            continue;
        }
        try (InternalSiteServiceClient client = new InternalSiteServiceClient(remoteSite, coordinator, apiSignatureGenerator)) {
            SiteList sites = client.getSiteList();
            if (!isActiveSite(remoteSite.getUuid(), sites)) {
                continue;
            }
            if (isSiteContainedBy(localSite.getUuid(), sites)) {
                return response;
            } else {
                log.info("According returned result from current active site {}, local site {} has been removed", remoteSite.getUuid(), localSite.getUuid());
                response.setIsRemoved(true);
                return response;
            }
        } catch (Exception e) {
            log.warn("Error happened when fetching site list from site {}", remoteSite.getUuid(), e);
            continue;
        }
    }
    return response;
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteList(com.emc.storageos.model.dr.SiteList) SiteRemoved(com.emc.storageos.model.dr.SiteRemoved) InternalSiteServiceClient(com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient) 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)

Example 3 with InternalSiteServiceClient

use of com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method doSwitchover.

/**
 * Do Site Switchover
 * This API will do switchover to target new active site according passed in site UUID. After failover, old active site will
 * work as normal standby site and target site will be promoted to active. All site will update properties to trigger reconfig.
 *
 * @param uuid target new active site UUID
 * @brief Do site switchover
 * @return return accepted response if operation is successful
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{uuid}/switchover")
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN }, blockProxies = true)
public Response doSwitchover(@PathParam("uuid") String uuid) {
    log.info("Begin to switchover for standby UUID {}", uuid);
    precheckForSwitchoverForActiveSite(uuid);
    List<Site> allStandbySites = drUtil.listStandbySites();
    for (Site site : allStandbySites) {
        if (!site.getUuid().equals(uuid) && site.getState() == SiteState.STANDBY_PAUSED) {
            try (InternalSiteServiceClient client = new InternalSiteServiceClient(site)) {
                client.setCoordinatorClient(coordinator);
                client.setKeyGenerator(apiSignatureGenerator);
                client.switchoverPrecheck();
            }
        }
    }
    String oldActiveUUID = drUtil.getActiveSite().getUuid();
    InterProcessLock lock = drUtil.getDROperationLock();
    Site newActiveSite = null;
    Site oldActiveSite = null;
    try {
        newActiveSite = drUtil.getSiteFromLocalVdc(uuid);
        // Set old active site's state, short id and key
        oldActiveSite = drUtil.getSiteFromLocalVdc(oldActiveUUID);
        if (StringUtils.isEmpty(oldActiveSite.getSiteShortId())) {
            oldActiveSite.setSiteShortId(newActiveSite.getVdcShortId());
        }
        coordinator.startTransaction();
        oldActiveSite.setState(SiteState.ACTIVE_SWITCHING_OVER);
        coordinator.persistServiceConfiguration(oldActiveSite.toConfiguration());
        // this barrier is set when begin switchover and will be removed by new active site. Old active site will wait and reboot after
        // barrier is removed
        DistributedBarrier restartBarrier = coordinator.getDistributedBarrier(String.format("%s/%s/%s", ZkPath.SITES, oldActiveSite.getUuid(), Constants.SWITCHOVER_BARRIER_RESTART));
        restartBarrier.setBarrier();
        drUtil.recordDrOperationStatus(oldActiveSite.getUuid(), InterState.SWITCHINGOVER_ACTIVE);
        // trigger reconfig
        // a version for all sites.
        long vdcConfigVersion = DrUtil.newVdcConfigVersion();
        for (Site eachSite : drUtil.listSites()) {
            if (!eachSite.getUuid().equals(uuid) && eachSite.getState() == SiteState.STANDBY_PAUSED) {
                try (InternalSiteServiceClient client = new InternalSiteServiceClient(eachSite)) {
                    client.setCoordinatorClient(coordinator);
                    client.setKeyGenerator(apiSignatureGenerator);
                    client.switchover(newActiveSite.getUuid(), vdcConfigVersion);
                }
            } else {
                drUtil.updateVdcTargetVersion(eachSite.getUuid(), SiteInfo.DR_OP_SWITCHOVER, vdcConfigVersion, oldActiveSite.getUuid(), newActiveSite.getUuid());
            }
        }
        coordinator.commitTransaction();
        auditDisasterRecoveryOps(OperationTypeEnum.SWITCHOVER, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, oldActiveSite.toBriefString(), newActiveSite.toBriefString());
        return Response.status(Response.Status.ACCEPTED).build();
    } catch (Exception e) {
        log.error(String.format("Error happened when switchover from site %s to site %s", oldActiveUUID, uuid), e);
        coordinator.discardTransaction();
        auditDisasterRecoveryOps(OperationTypeEnum.SWITCHOVER, AuditLogManager.AUDITLOG_FAILURE, null, newActiveSite.getName(), newActiveSite.getVipEndPoint());
        throw APIException.internalServerErrors.switchoverFailed(oldActiveSite.getName(), newActiveSite.getName(), e.getMessage());
    } finally {
        try {
            lock.release();
        } catch (Exception ignore) {
            log.error(String.format("Lock release failed when switchover from %s to %s", oldActiveUUID, uuid));
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) InternalSiteServiceClient(com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient) DistributedBarrier(org.apache.curator.framework.recipes.barriers.DistributedBarrier) 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) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with InternalSiteServiceClient

use of com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient 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));
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SecretKey(javax.crypto.SecretKey) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SiteState(com.emc.storageos.coordinator.client.model.SiteState) InternalSiteServiceClient(com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient) SiteNetworkState(com.emc.storageos.coordinator.client.model.SiteNetworkState) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) SiteConfigParam(com.emc.storageos.model.dr.SiteConfigParam) 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) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

InternalSiteServiceClient (com.emc.storageos.api.service.impl.resource.utils.InternalSiteServiceClient)4 Site (com.emc.storageos.coordinator.client.model.Site)4 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)4 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)4 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)4 ZkPath (com.emc.storageos.coordinator.common.impl.ZkPath)3 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)3 UnknownHostException (java.net.UnknownHostException)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 POST (javax.ws.rs.POST)2 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)2 SiteInfo (com.emc.storageos.coordinator.client.model.SiteInfo)1 SiteNetworkState (com.emc.storageos.coordinator.client.model.SiteNetworkState)1 SiteState (com.emc.storageos.coordinator.client.model.SiteState)1 Configuration (com.emc.storageos.coordinator.common.Configuration)1 SiteConfigParam (com.emc.storageos.model.dr.SiteConfigParam)1 SiteList (com.emc.storageos.model.dr.SiteList)1 SiteRemoved (com.emc.storageos.model.dr.SiteRemoved)1