Search in sources :

Example 11 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.

the class GeoServiceHelper method nextVdcId.

private int nextVdcId() {
    int max_id = 0;
    // include the inactive ones
    List<URI> vdcIds = _dbClient.queryByType(VirtualDataCenter.class, false);
    for (URI vdcId : vdcIds) {
        VirtualDataCenter vdc = _dbClient.queryObject(VirtualDataCenter.class, vdcId);
        String id = vdc.getShortId().replace(VDC_ID_PREFIX, "");
        int num = Integer.parseInt(id);
        if (num > max_id) {
            max_id = num;
        }
    }
    return max_id + 1;
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 12 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.

the class GeoServiceHelper method prepareVirtualDataCenter.

public static VirtualDataCenter prepareVirtualDataCenter(URI vdcId, VirtualDataCenter.ConnectionStatus connStatus, VirtualDataCenter.GeoReplicationStatus replicationStatus, Properties vdcProp) {
    VirtualDataCenter vdc = new VirtualDataCenter();
    vdc.setId(vdcId);
    vdc.setShortId(vdcProp.getProperty(GeoServiceJob.VDC_SHORT_ID));
    vdc.setConnectionStatus(connStatus);
    vdc.setRepStatus(replicationStatus);
    Date init_date = new Date();
    // timestamp for the new vdc record
    vdc.setVersion(init_date.getTime());
    vdc.setLocal(false);
    vdc.setLabel(vdcProp.getProperty(GeoServiceJob.VDC_NAME));
    vdc.setApiEndpoint(vdcProp.getProperty(GeoServiceJob.VDC_API_ENDPOINT));
    vdc.setSecretKey(vdcProp.getProperty(GeoServiceJob.VDC_SECRETE_KEY));
    vdc.setDescription(vdcProp.getProperty(GeoServiceJob.VDC_DESCRIPTION));
    vdc.setGeoCommandEndpoint(vdcProp.getProperty(GeoServiceJob.VDC_GEODATA_ENDPOINT));
    vdc.setGeoDataEndpoint(vdcProp.getProperty(GeoServiceJob.VDC_GEODATA_ENDPOINT));
    vdc.setCertificateChain(vdcProp.getProperty(GeoServiceJob.VDC_CERTIFICATE_CHAIN));
    return vdc;
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) Date(java.util.Date)

Example 13 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.

the class RequestedTokenHelper method broadcastLogoutForce.

/**
 * Iterates through the list of VDCs, skips the local vdc, and sends a logout?force=true request to
 * each vdc found, with optionally the ?username= parameter if supplied.
 *
 * @param rawToken
 * @param username optional
 */
public void broadcastLogoutForce(String rawToken, String username) {
    List<URI> vdcIds = dbClient.queryByType(VirtualDataCenter.class, true);
    Iterator<VirtualDataCenter> vdcIter = dbClient.queryIterativeObjects(VirtualDataCenter.class, vdcIds);
    while (vdcIter.hasNext()) {
        VirtualDataCenter vdc = vdcIter.next();
        if (vdc.getShortId().equals(VdcUtil.getLocalShortVdcId())) {
            log.info("Skipping local vdc.  Already proceeded logout?force locally");
            continue;
        }
        try {
            ClientResponse resp = geoClientCacheMgt.getGeoClient(vdc.getShortId()).logoutToken(rawToken, username, true);
        } catch (Exception e) {
            log.error("Could not contact remote VDC to invalidate token with force option: {}", vdc.getShortId());
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI) RetryableSecurityException(com.emc.storageos.security.exceptions.RetryableSecurityException) SecurityException(com.emc.storageos.security.exceptions.SecurityException)

Example 14 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.

the class VdcConfigService method resetBlackListForVdc.

@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/resetblacklist")
public Response resetBlackListForVdc(@QueryParam("vdc_short_id") String vdcShortId) {
    try {
        log.info("Reset blacklist for {}", vdcShortId);
        URI vdcId = VdcUtil.getVdcUrn(vdcShortId);
        VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, vdcId);
        dbClient.removeVdcNodesFromBlacklist(vdc);
        return Response.ok().build();
    } catch (InternalException ex) {
        throw ex;
    } catch (Exception ex) {
        log.error("Reset blacklist vdc error", ex);
        throw GeoException.fatals.reconnectVdcIncompatible();
    }
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 15 with VirtualDataCenter

use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.

the class VdcConfigService method precheckVdcConfig.

/**
 * Retrieve the vdc config info of the current site, return such info with precheck.
 * 1. For adding a new vdc, the current vdc should be in ISOLATED status and is a fresh installation.
 * 2. For updating an existing vdc, the current vdc should be in CONNECTED status.
 *
 * @param checkParam
 *
 * @return VirtualDataCenterResponse
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/precheck")
public VdcPreCheckResponse precheckVdcConfig(VdcPreCheckParam checkParam) {
    log.info("Start vdc config precheck for {} ...", checkParam.getConfigChangeType());
    if (service.getId().endsWith("standalone")) {
        throw GeoException.fatals.remoteVDCWrongStandaloneInstall();
    }
    log.info("Loading local vdc config ...");
    VirtualDataCenter vdc = VdcUtil.getLocalVdc();
    Boolean isFresher = checkParam.getFresher();
    if (isFresher != null && isFresher) {
        // check if VDC is a fresh installation, in ISOLATED status
        if (VirtualDataCenter.ConnectionStatus.ISOLATED != vdc.getConnectionStatus()) {
            throw GeoException.fatals.remoteFreshVDCWrongStatus(vdc.getId());
        }
    } else {
        // check if VDC is in CONNECTED status- remove, add; update will skip-CTRL3549
        if (checkParam.getConfigChangeType().equals(VdcConfig.ConfigChangeType.CONNECT_VDC.toString()) || (checkParam.getConfigChangeType().equals(VdcConfig.ConfigChangeType.REMOVE_VDC.toString()))) {
            if (vdc.getConnectionStatus() != VirtualDataCenter.ConnectionStatus.CONNECTED) {
                throw GeoException.fatals.remoteVDCWrongOperationStatus(vdc.getId(), checkParam.getConfigChangeType());
            }
        }
    }
    boolean hasData = false;
    if (isFresher) {
        hasData = dbClient.hasUsefulData();
    }
    hasData |= hasDataService();
    log.info("Checking software version ...");
    SoftwareVersion remoteSoftVer = null;
    try {
        remoteSoftVer = new SoftwareVersion(checkParam.getSoftwareVersion());
        log.info("Software version of remote vdc: {}", remoteSoftVer);
    } catch (Exception e) {
        log.info("Cannot get software version from checkParam, the version of remote vdc is lower than v2.3 with exception {}", e.getMessage());
    }
    SoftwareVersion localSoftVer;
    try {
        localSoftVer = coordinator.getTargetInfo(RepositoryInfo.class).getCurrentVersion();
    } catch (Exception ex) {
        throw GeoException.fatals.remoteVDCFailedToGetVersion(vdc.getId());
    }
    return toVirtualDataCenterResponse(vdc, hasData, remoteSoftVer, localSoftVer);
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

VirtualDataCenter (com.emc.storageos.db.client.model.VirtualDataCenter)80 URI (java.net.URI)47 ArrayList (java.util.ArrayList)20 VdcConfig (com.emc.storageos.geomodel.VdcConfig)14 GeoException (com.emc.storageos.security.geo.exceptions.GeoException)13 Test (org.junit.Test)10 Site (com.emc.storageos.coordinator.client.model.Site)7 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 VdcConfigSyncParam (com.emc.storageos.geomodel.VdcConfigSyncParam)7 FatalGeoException (com.emc.storageos.security.geo.exceptions.FatalGeoException)7 NamedURI (com.emc.storageos.db.client.model.NamedURI)6 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)5 Produces (javax.ws.rs.Produces)5 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)4 DataObject (com.emc.storageos.db.client.model.DataObject)4 TestGeoObject (com.emc.storageos.db.client.model.TestGeoObject)4 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)4 KeyStoreException (java.security.KeyStoreException)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4