Search in sources :

Example 56 with Site

use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method retryOperation.

/**
 * Query the latest error message & Retry the Last operation for specific standby site
 *
 * @param uuid site UUID
 * @brief Query the latest error message & Retry the Last operation for specific 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 })
@Path("/{uuid}/retry")
public SiteRestRep retryOperation(@PathParam("uuid") String uuid) {
    log.info("Begin to get site error by uuid {}", uuid);
    Site standby;
    try {
        standby = drUtil.getSiteFromLocalVdc(uuid);
    } catch (CoordinatorException e) {
        log.error("Can't find site {} from ZK", uuid);
        throw APIException.badRequests.siteIdNotFound();
    }
    if (!standby.getState().equals(SiteState.STANDBY_ERROR)) {
        log.error("site {} is in state {}, should be STANDBY_ERROR", uuid, standby.getState());
        throw APIException.badRequests.operationOnlyAllowedOnErrorSite(standby.getName(), standby.getState().toString());
    }
    if (!standby.getLastState().equals(SiteState.STANDBY_PAUSING) && !standby.getLastState().equals(SiteState.STANDBY_RESUMING) && !standby.getLastState().equals(SiteState.STANDBY_FAILING_OVER)) {
        log.error("site {} lastState was {}, retry is only supported for Pause, Resume and Failover", uuid, standby.getLastState());
        throw APIException.badRequests.operationRetryOnlyAllowedOnLastState(standby.getName(), standby.getLastState().toString());
    }
    // Reuse the current action required
    Site localSite = drUtil.getLocalSite();
    SiteInfo siteInfo = coordinator.getTargetInfo(localSite.getUuid(), SiteInfo.class);
    String drOperation = siteInfo.getActionRequired();
    // Check that last action matches retry action
    if (!drOperation.equals(standby.getLastState().getDRAction())) {
        log.error("Active site last operation was {}, retry is only supported if no other operations have been performed", drOperation);
        throw APIException.internalServerErrors.retryStandbyPrecheckFailed(standby.getName(), standby.getLastState().toString(), String.format("Another DR operation %s has been run on Active site. Only the latest operation can be retried. " + "This is an unrecoverable Error, please remove site and deploy a new one.", drOperation));
    }
    InterProcessLock lock = drUtil.getDROperationLock();
    try {
        coordinator.startTransaction();
        standby.setState(standby.getLastState());
        // Failover requires setting old active site to last state as well.
        if (standby.getState() == SiteState.STANDBY_FAILING_OVER) {
            for (Site site : drUtil.listSites()) {
                if (site.getLastState() == SiteState.ACTIVE_FAILING_OVER) {
                    site.setState(SiteState.ACTIVE_FAILING_OVER);
                    coordinator.persistServiceConfiguration(site.toConfiguration());
                }
            }
        }
        coordinator.persistServiceConfiguration(standby.toConfiguration());
        log.info("Notify all sites for reconfig");
        long vdcTargetVersion = DrUtil.newVdcConfigVersion();
        for (Site site : drUtil.listSites()) {
            String siteUuid = site.getUuid();
            if (site.getLastState() == SiteState.STANDBY_RESUMING) {
                SiteInfo siteTargetInfo = coordinator.getTargetInfo(siteUuid, SiteInfo.class);
                String resumeSiteOperation = siteTargetInfo.getActionRequired();
                if (resumeSiteOperation.equals(SiteInfo.DR_OP_CHANGE_DATA_REVISION)) {
                    long dataRevision = vdcTargetVersion;
                    drUtil.updateVdcTargetVersion(siteUuid, resumeSiteOperation, vdcTargetVersion, dataRevision);
                    continue;
                }
            }
            log.info("Set dr operation {} on site {}", drOperation, siteUuid);
            drUtil.updateVdcTargetVersion(siteUuid, drOperation, vdcTargetVersion);
        }
        coordinator.commitTransaction();
        return siteMapper.map(standby);
    } catch (Exception e) {
        log.error("Error retrying site operation for site {}", uuid, e);
        coordinator.discardTransaction();
        auditDisasterRecoveryOps(OperationTypeEnum.RETRY_STANDBY_OP, AuditLogManager.AUDITLOG_FAILURE, null, standby);
        InternalServerErrorException retryStandbyOpFailedException = APIException.internalServerErrors.retryStandbyOpFailed(standby.getName(), e.getMessage());
        throw retryStandbyOpFailedException;
    } finally {
        try {
            lock.release();
        } catch (Exception ignore) {
            log.error(String.format("Lock release failed when retrying standby site last op: %s", uuid));
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteInfo(com.emc.storageos.coordinator.client.model.SiteInfo) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) 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 57 with Site

use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method switchover.

/**
 * This is internal API to do switchover
 *
 * @return return response with error message and service code
 */
@POST
@Path("/internal/switchover")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response switchover(@QueryParam("newActiveSiteUUid") String newActiveSiteUUID, @QueryParam("vdcVersion") String vdcTargetVersion) {
    log.info("Begin to switchover internally for standby UUID {}", newActiveSiteUUID);
    Site newActiveSite = null;
    Site oldActiveSite = null;
    try {
        newActiveSite = drUtil.getSiteFromLocalVdc(newActiveSiteUUID);
        oldActiveSite = drUtil.getSiteFromLocalVdc(drUtil.getActiveSite().getUuid());
        if (StringUtils.isEmpty(oldActiveSite.getSiteShortId())) {
            oldActiveSite.setSiteShortId(newActiveSite.getVdcShortId());
        }
        oldActiveSite.setState(SiteState.STANDBY_SYNCED);
        coordinator.persistServiceConfiguration(oldActiveSite.toConfiguration());
        newActiveSite.setState(SiteState.ACTIVE);
        coordinator.persistServiceConfiguration(newActiveSite.toConfiguration());
        drUtil.updateVdcTargetVersion(drUtil.getLocalSite().getUuid(), SiteInfo.DR_OP_SWITCHOVER, Long.parseLong(vdcTargetVersion), oldActiveSite.getUuid(), newActiveSite.getUuid());
        return Response.status(Response.Status.ACCEPTED).build();
    } catch (Exception e) {
        log.error(String.format("Error happened when switchover to site %s", newActiveSiteUUID), e);
        throw APIException.internalServerErrors.switchoverFailed(oldActiveSite.getName(), newActiveSite.getName(), e.getMessage());
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) 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)

Example 58 with Site

use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method getSites.

/**
 * Get all sites including standby and active
 *
 * @brief Get all standby and active sites of local VDC
 * @return site list contains all sites 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 })
public SiteList getSites() {
    log.info("Begin to list all standby sites of local VDC");
    SiteList standbyList = new SiteList();
    for (Site site : drUtil.listSites()) {
        standbyList.getSites().add(siteMapper.mapWithNetwork(site, drUtil));
    }
    SiteInfo siteInfo = coordinator.getTargetInfo(coordinator.getSiteId(), SiteInfo.class);
    standbyList.setConfigVersion(siteInfo.getVdcConfigVersion());
    return standbyList;
}
Also used : SiteList(com.emc.storageos.model.dr.SiteList) Site(com.emc.storageos.coordinator.client.model.Site) SiteInfo(com.emc.storageos.coordinator.client.model.SiteInfo) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 59 with Site

use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method precheckForSwitchoverForActiveSite.

protected void precheckForSwitchoverForActiveSite(String standbyUuid) {
    Site standby = null;
    if (drUtil.isStandby()) {
        throw APIException.badRequests.operationOnlyAllowedOnActiveSite();
    }
    try {
        standby = drUtil.getSiteFromLocalVdc(standbyUuid);
    } catch (CoordinatorException e) {
        throw APIException.internalServerErrors.switchoverPrecheckFailed(standby.getUuid(), "Standby uuid is not valid, can't find it");
    }
    if (standbyUuid.equals(drUtil.getActiveSite().getUuid())) {
        throw APIException.internalServerErrors.switchoverPrecheckFailed(standby.getName(), "Can't switchover to an active site");
    }
    if (standby.getState() != SiteState.STANDBY_SYNCED) {
        throw APIException.internalServerErrors.switchoverPrecheckFailed(standby.getName(), "Standby site is not fully synced");
    }
    if (!drUtil.isSiteUp(standbyUuid)) {
        throw APIException.internalServerErrors.switchoverPrecheckFailed(standby.getName(), "Standby site is not up");
    }
    if (coordinator.getControlNodesState(standby.getUuid()) != ClusterInfo.ClusterState.STABLE) {
        throw APIException.internalServerErrors.switchoverPrecheckFailed(standby.getName(), "Standby site is not stable");
    }
    if (!isClusterStable()) {
        throw APIException.internalServerErrors.switchoverPrecheckFailed(standby.getName(), "Active site is not stable");
    }
    checkSiteConnectivity(standby);
    List<Site> existingSites = drUtil.listStandbySites();
    for (Site site : existingSites) {
        if (site.getState() != SiteState.STANDBY_SYNCED && site.getState() != SiteState.STANDBY_PAUSED) {
            throw APIException.internalServerErrors.switchoverPrecheckFailed(standby.getName(), String.format("Standby site %s is not synced or paused", site.getName()));
        }
        ClusterInfo.ClusterState state = coordinator.getControlNodesState(site.getUuid());
        if (site.getState() != SiteState.STANDBY_PAUSED && state != ClusterInfo.ClusterState.STABLE) {
            log.info("Site {} is not stable {}", site.getUuid(), state);
            throw APIException.internalServerErrors.switchoverPrecheckFailed(standby.getName(), String.format("Site %s is not stable", site.getName()));
        }
    }
}
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)

Example 60 with Site

use of com.emc.storageos.coordinator.client.model.Site in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method doFailover.

/**
 * Do Site Fail over
 *
 * This API will do failover from standby site. This operation is only allowed when active site is down.
 * After failover, this standby site will be promoted to active site.
 *
 * @param uuid target new active site UUID
 * @brief Do site failover
 * @return return accepted response if operation is successful
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{uuid}/failover")
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.RESTRICTED_SECURITY_ADMIN }, blockProxies = true)
public Response doFailover(@PathParam("uuid") String uuid) {
    log.info("Begin to failover for standby UUID {}", uuid);
    Site currentSite = drUtil.getSiteFromLocalVdc(uuid);
    precheckForFailoverLocally(uuid);
    List<Site> allStandbySites = drUtil.listStandbySites();
    try {
        coordinator.startTransaction();
        // set state
        String activeSiteId = drUtil.getActiveSite().getUuid();
        Site oldActiveSite = new Site();
        if (StringUtils.isEmpty(activeSiteId)) {
            log.info("Cant't find active site id, go on to do failover");
        } else {
            oldActiveSite = drUtil.getSiteFromLocalVdc(activeSiteId);
            oldActiveSite.setState(SiteState.ACTIVE_FAILING_OVER);
            coordinator.persistServiceConfiguration(oldActiveSite.toConfiguration());
        }
        currentSite.setState(SiteState.STANDBY_FAILING_OVER);
        coordinator.persistServiceConfiguration(currentSite.toConfiguration());
        drUtil.recordDrOperationStatus(currentSite.getUuid(), InterState.FAILINGOVER_STANDBY);
        long vdcTargetVersion = DrUtil.newVdcConfigVersion();
        // reconfig other standby sites
        for (Site site : allStandbySites) {
            if (!site.getUuid().equals(uuid)) {
                if (site.getState() == SiteState.STANDBY_SYNCED) {
                    site.setState(SiteState.STANDBY_PAUSED);
                    coordinator.persistServiceConfiguration(site.toConfiguration());
                } else if (site.getState() == SiteState.STANDBY_REMOVING) {
                    site.setState(SiteState.STANDBY_ERROR);
                    coordinator.persistServiceConfiguration(site.toConfiguration());
                }
                // update the vdc config version on the new active site.
                drUtil.updateVdcTargetVersion(site.getUuid(), SiteInfo.DR_OP_FAILOVER, vdcTargetVersion, oldActiveSite.getUuid(), currentSite.getUuid());
            }
        }
        drUtil.updateVdcTargetVersion(uuid, SiteInfo.DR_OP_FAILOVER, vdcTargetVersion, oldActiveSite.getUuid(), currentSite.getUuid());
        coordinator.commitTransaction();
        auditDisasterRecoveryOps(OperationTypeEnum.FAILOVER, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, oldActiveSite.toBriefString(), currentSite.toBriefString());
        return Response.status(Response.Status.ACCEPTED).build();
    } catch (Exception e) {
        log.error("Error happened when failover at site {}", uuid, e);
        coordinator.discardTransaction();
        auditDisasterRecoveryOps(OperationTypeEnum.FAILOVER, AuditLogManager.AUDITLOG_FAILURE, null, currentSite.getName(), currentSite.getVipEndPoint());
        throw APIException.internalServerErrors.failoverFailed(currentSite.getName(), e.getMessage());
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) 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

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