Search in sources :

Example 11 with SiteInfo

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

the class DisasterRecoveryServiceTest method testGetAllStandby.

@Test
public void testGetAllStandby() throws Exception {
    List<Site> sites = new ArrayList<>();
    sites.add(standbySite1);
    sites.add(standbySite2);
    sites.add(standbySite3);
    doReturn(sites).when(drUtil).listSites();
    doReturn(new SiteInfo()).when(coordinator).getTargetInfo(any(String.class), eq(SiteInfo.class));
    SiteList responseList = drService.getSites();
    assertNotNull(responseList.getSites());
    assertEquals(3, responseList.getSites().size());
    compareSiteResponse(responseList.getSites().get(0), standbySite1);
    compareSiteResponse(responseList.getSites().get(1), standbySite2);
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteList(com.emc.storageos.model.dr.SiteList) SiteInfo(com.emc.storageos.coordinator.client.model.SiteInfo) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 12 with SiteInfo

use of com.emc.storageos.coordinator.client.model.SiteInfo 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 SiteInfo

use of com.emc.storageos.coordinator.client.model.SiteInfo 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 14 with SiteInfo

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

the class VdcConfigService method getIpsecProperties.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/ipsec-properties")
public PropertyInfoRestRep getIpsecProperties() throws Exception {
    log.info("getting ipsec properties.");
    Map<String, String> ipsecProps = new HashMap();
    ipsecProps.put(IPSEC_KEY, ipsecConfig.getPreSharedKey());
    SiteInfo siteInfo = coordinator.getTargetInfo(SiteInfo.class);
    String vdcConfigVersion = String.valueOf(siteInfo.getVdcConfigVersion());
    ipsecProps.put(VDC_CONFIG_VERSION, vdcConfigVersion);
    log.info("ipsec key: " + ipsecConfig.getPreSharedKey() + ", vdc config version: " + vdcConfigVersion);
    return new PropertyInfoRestRep(ipsecProps);
}
Also used : SiteInfo(com.emc.storageos.coordinator.client.model.SiteInfo) PropertyInfoRestRep(com.emc.storageos.model.property.PropertyInfoRestRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

SiteInfo (com.emc.storageos.coordinator.client.model.SiteInfo)14 Site (com.emc.storageos.coordinator.client.model.Site)10 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)3 ArrayList (java.util.ArrayList)3 Produces (javax.ws.rs.Produces)3 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)2 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)2 PropertyInfoMapper.decodeFromString (com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)2 SiteList (com.emc.storageos.model.dr.SiteList)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 SiteState (com.emc.storageos.coordinator.client.model.SiteState)1 VdcConfigVersion (com.emc.storageos.coordinator.client.model.VdcConfigVersion)1 Service (com.emc.storageos.coordinator.common.Service)1 ZkPath (com.emc.storageos.coordinator.common.impl.ZkPath)1