Search in sources :

Example 46 with Site

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

the class StorageDriverManager method downloadDrivers.

private void downloadDrivers(Set<String> drivers) {
    for (String driver : drivers) {
        File driverFile = new File(TMP_DIR + driver);
        try {
            URI endPoint = null;
            if (drUtil.isActiveSite()) {
                endPoint = getSyncedNode(driver);
            } else {
                while (!hasActiveSiteFinishDownload(driver)) {
                    log.info("Sleep 5 seconds to wait active site finish downloading driver {}", driver);
                    waiter.sleep(5000);
                }
                Site activeSite = drUtil.getActiveSite();
                endPoint = URI.create(String.format(SysClientFactory.BASE_URL_FORMAT, activeSite.getVipEndPoint(), service.getEndpoint().getPort()));
                log.info("Endpoint has been substituted, new endpoint is: {}", endPoint.toString());
            }
            if (endPoint == null) {
                // should not happen
                log.error("Can't find node that hold driver file: {}", driver);
                continue;
            }
            String uri = SysClientFactory.URI_GET_DRIVER + "?name=" + driver;
            log.info("Prepare to download driver file {} from uri {}", driver, uri);
            InputStream in = SysClientFactory.getSysClient(endPoint).get(new URI(uri), InputStream.class, MediaType.APPLICATION_OCTET_STREAM);
            OutputStream os = new BufferedOutputStream(new FileOutputStream(driverFile));
            int bytesRead = 0;
            while (true) {
                byte[] buffer = new byte[0x10000];
                bytesRead = in.read(buffer);
                if (bytesRead == -1) {
                    break;
                }
                os.write(buffer, 0, bytesRead);
            }
            in.close();
            os.close();
            Files.move(driverFile, new File(DRIVER_DIR + driverFile.getName()));
            log.info("Driver {} has been downloaded from {}", driver, endPoint);
        } catch (Exception e) {
            log.error("Failed to download driver {} with exception", driver, e);
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) InputStream(java.io.InputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) URI(java.net.URI) BufferedOutputStream(java.io.BufferedOutputStream) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException)

Example 47 with Site

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

the class DrSiteNetworkMonitor method shouldStartOnCurrentSite.

/**
 * Whether we should bring up network monitor. Only active site(or degraded), or paused standby site need run network monitor
 *
 * @return true if we should start it
 */
private boolean shouldStartOnCurrentSite() {
    if (drUtil.isActiveSite()) {
        return true;
    }
    Site localSite = drUtil.getLocalSite();
    SiteState state = localSite.getState();
    if (state == SiteState.STANDBY_PAUSED || state == SiteState.ACTIVE_DEGRADED) {
        return true;
    }
    _log.debug("This site is not active site or standby paused, no need to do network monitor");
    return false;
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteState(com.emc.storageos.coordinator.client.model.SiteState)

Example 48 with Site

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

the class DrZkHealthMonitor method checkAndUpdateLocalSiteState.

/**
 * Update the standby site state when the active site is lost.
 * if SYNCED, change it to PAUSED.
 * if SYNCING/RESUMING/ADDING, change it to ERROR since it will never finish without the active site.
 */
private void checkAndUpdateLocalSiteState() {
    Site localSite = drUtil.getLocalSite();
    SiteState state = localSite.getState();
    if (SiteState.STANDBY_SYNCED.equals(state) || SiteState.STANDBY_INCR_SYNCING.equals(state)) {
        log.info("Updating local site from {} to STANDBY_PAUSED since active is unreachable", state);
        localSite.setState(SiteState.STANDBY_PAUSED);
        coordinatorExt.getCoordinatorClient().persistServiceConfiguration(localSite.toConfiguration());
        coordinatorExt.rescheduleDrSiteNetworkMonitor();
    } else if (SiteState.STANDBY_SYNCING.equals(state) || SiteState.STANDBY_RESUMING.equals(state) || SiteState.STANDBY_ADDING.equals(state)) {
        log.info("Updating local site from {} to STANDBY_ERROR since active is unreachable", localSite.getState());
        localSite.setLastState(state);
        localSite.setState(SiteState.STANDBY_ERROR);
        coordinatorExt.getCoordinatorClient().persistServiceConfiguration(localSite.toConfiguration());
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteState(com.emc.storageos.coordinator.client.model.SiteState)

Example 49 with Site

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

the class StorageDriverService method precheckForEnv.

protected void precheckForEnv() {
    DrUtil drUtil = new DrUtil(coordinator);
    if (!drUtil.isActiveSite()) {
        throw APIException.internalServerErrors.driverOperationEnvPrecheckFailed("This operation is not allowed on standby site");
    }
    for (Site site : drUtil.listSites()) {
        SiteState siteState = site.getState();
        if (!siteState.equals(SiteState.ACTIVE) && !siteState.equals(SiteState.STANDBY_SYNCED)) {
            throw APIException.internalServerErrors.driverOperationEnvPrecheckFailed(String.format("Site %s is in %s state,not active or synced", site.getName(), siteState));
        }
        ClusterInfo.ClusterState state = coordinator.getControlNodesState(site.getUuid());
        if (state != ClusterInfo.ClusterState.STABLE) {
            throw APIException.internalServerErrors.driverOperationEnvPrecheckFailed(String.format("Currently site %s is not stable", site.getName()));
        }
    }
    // driver operations and order executions to avoid impact on each other.
    if (hasOngoingQueuedOrders()) {
        throw APIException.internalServerErrors.driverOperationEnvPrecheckFailed("There are ongoing or queued orders now, please wait until these orders complete");
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) SiteState(com.emc.storageos.coordinator.client.model.SiteState) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil)

Example 50 with Site

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

the class IPsecManager method updateTargetSiteInfo.

private String updateTargetSiteInfo(long vdcConfigVersion) {
    for (Site site : drUtil.listSites()) {
        SiteInfo siteInfo;
        String siteId = site.getUuid();
        SiteInfo currentSiteInfo = coordinator.getTargetInfo(siteId, SiteInfo.class);
        if (currentSiteInfo != null) {
            siteInfo = new SiteInfo(vdcConfigVersion, SiteInfo.IPSEC_OP_ROTATE_KEY, currentSiteInfo.getTargetDataRevision(), SiteInfo.ActionScope.VDC);
        } else {
            siteInfo = new SiteInfo(vdcConfigVersion, SiteInfo.IPSEC_OP_ROTATE_KEY, SiteInfo.ActionScope.VDC);
        }
        coordinator.setTargetInfo(siteId, siteInfo);
        log.info("VDC target version updated to {} for site {}", siteInfo.getVdcConfigVersion(), siteId);
    }
    return Long.toString(vdcConfigVersion);
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SiteInfo(com.emc.storageos.coordinator.client.model.SiteInfo)

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