Search in sources :

Example 11 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException 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));
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) StringMap(com.emc.storageos.db.client.model.StringMap) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) ArrayList(java.util.ArrayList) 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) Date(java.util.Date) SecretKey(javax.crypto.SecretKey) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) SiteConfigRestRep(com.emc.storageos.model.dr.SiteConfigRestRep) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 12 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException 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 13 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method failoverPrecheck.

/**
 * This is internal API to do precheck for failover
 *
 * @return return response with error message and service code
 */
@POST
@Path("/internal/failoverprecheck")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public FailoverPrecheckResponse failoverPrecheck() {
    log.info("Precheck for failover internally");
    FailoverPrecheckResponse response = new FailoverPrecheckResponse();
    response.setSite(this.siteMapper.map(drUtil.getLocalSite()));
    try {
        precheckForFailover();
    } catch (InternalServerErrorException e) {
        log.warn("Failed to precheck failover", e);
        response.setErrorMessage(e.getMessage());
        response.setServiceCode(e.getServiceCode().ordinal());
        return response;
    } catch (Exception e) {
        log.error("Failed to precheck failover", e);
        response.setErrorMessage(e.getMessage());
        return response;
    }
    return response;
}
Also used : FailoverPrecheckResponse(com.emc.storageos.model.dr.FailoverPrecheckResponse) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) 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)

Example 14 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException 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)

Example 15 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.

the class CustomServicesUtils method waitForTasks.

public static Map<URI, String> waitForTasks(final List<URI> tasksStartedByOe, final ViPRCoreClient client) throws InternalServerErrorException {
    if (tasksStartedByOe.isEmpty()) {
        throw InternalServerErrorException.internalServerErrors.customServiceNoTaskFound("No tasks to wait for");
    }
    ExecutionUtils.currentContext().logInfo("customServicesService.waitforTask");
    final long startTime = System.currentTimeMillis();
    final TaskState states = new TaskState(client, tasksStartedByOe);
    while (states.hasPending()) {
        states.updateState();
        try {
            checkTimeout(startTime);
        } catch (final InternalServerErrorException e) {
            states.printTaskState();
            throw e;
        }
    }
    return states.getTaskState();
}
Also used : InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) TaskState(com.emc.sa.service.vipr.customservices.tasks.TaskState)

Aggregations

InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)15 Test (org.junit.Test)7 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)6 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)5 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)5 UnknownHostException (java.net.UnknownHostException)5 POST (javax.ws.rs.POST)5 Produces (javax.ws.rs.Produces)5 Site (com.emc.storageos.coordinator.client.model.Site)4 ZkPath (com.emc.storageos.coordinator.common.impl.ZkPath)4 Path (javax.ws.rs.Path)4 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)3 DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)3 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 Response (javax.ws.rs.core.Response)3 StreamingOutput (javax.ws.rs.core.StreamingOutput)3 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)3 MonitoringService (com.emc.storageos.api.service.impl.resource.MonitoringService)2 DbEventRetriever (com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever)2 SiteConfigParam (com.emc.storageos.model.dr.SiteConfigParam)2