Search in sources :

Example 31 with VirtualDataCenter

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

the class ConnectVdcTaskOp method checkAndSync.

/**
 * Precheck if vdc connect is permitted, then sync the new vdc config to all sites
 */
private void checkAndSync(InternalApiSignatureKeyGenerator apiSignatureGenerator, KeyStore keystore) {
    String shortId = vdcInfo.getProperty(GeoServiceJob.VDC_SHORT_ID);
    String vdcName = vdcInfo.getProperty(GeoServiceJob.VDC_NAME);
    lockHelper.acquire(shortId);
    log.info("Acquired global lock, go on with connect vdc");
    geoClientCache.clearCache();
    loadVdcInfo();
    // Check & verify connection status of my current vdc
    preSteps();
    // Have the certificate for the to be added vdc
    persistVdcCert(vdcName, vdcInfo.getProperty(GeoServiceJob.VDC_CERTIFICATE_CHAIN), true, shortId);
    // precheck
    VdcPreCheckResponse operatedVdcInfo = preCheck();
    // remove root's Tenant Roles or project ownerships in local vdc
    try {
        _permissionHelper.removeRootRoleAssignmentOnTenantAndProject();
    } catch (DatabaseException dbe) {
        throw GeoException.fatals.connectVdcRemoveRootRolesFailed(dbe);
    }
    String currentVdcIpsecKey = ipsecConfig.getPreSharedKeyFromZK();
    URI newVdcId = URIUtil.uri(vdcInfo.getProperty(GeoServiceJob.OPERATED_VDC_ID));
    GeoServiceHelper.backupOperationVdc(dbClient, JobType.VDC_CONNECT_JOB, newVdcId, null);
    VirtualDataCenter newVdc = GeoServiceHelper.prepareVirtualDataCenter(newVdcId, VirtualDataCenter.ConnectionStatus.CONNECTING, VirtualDataCenter.GeoReplicationStatus.REP_NONE, vdcInfo);
    dbClient.createObject(newVdc);
    helper.createVdcConfigInZk(mergeVdcInfo(operatedVdcInfo), currentVdcIpsecKey);
    // we should use uuid as cert name in trust store, but before we persist new vdc info
    // into db, we use vdc name as cert name, after we persist new vdc into db, persist uuid
    // as cert name and remove the one which use vdc name as cert name.
    persistVdcCert(newVdc.getId().toString(), newVdc.getCertificateChain(), true, shortId);
    removeVdcCert(vdcName, shortId);
    // add new remote VDC to the list of VDC to sync
    toBeSyncedVdc.add(newVdc);
    allVdc.add(newVdc);
    connectedVdc.add(newVdc);
    VdcUtil.invalidateVdcUrnCache();
    // Now set "operatedVdc as the newly created VDC
    operatedVdc = newVdc;
    // generate the cert chain to be synced
    VdcCertListParam certListParam = genCertListParam(VdcCertListParam.CMD_ADD_CERT);
    // from now on, vdc status will be marked as CONNECT_FAILED for any failure
    failedVdcStatus = ConnectionStatus.CONNECT_FAILED;
    // sync the new certificate to all connected sites
    syncCerts(VdcCertListParam.CMD_ADD_CERT, certListParam);
    VdcConfigSyncParam mergedVdcInfo = configMerge(operatedVdcInfo, currentVdcIpsecKey);
    if (mergedVdcInfo == null) {
        log.error("merge the vdc config of all sites failed");
        throw GeoException.fatals.mergeConfigFail();
    }
    try {
        configSync(mergedVdcInfo);
    } catch (GeoException ex) {
        throw ex;
    } catch (Exception e) {
        log.error("Failed to sync vdc config to all sites e=", e);
        throw GeoException.fatals.syncConfigFail(e);
    }
// do not release the global lock here; lock is released during post processing
}
Also used : VdcConfigSyncParam(com.emc.storageos.geomodel.VdcConfigSyncParam) VdcPreCheckResponse(com.emc.storageos.geomodel.VdcPreCheckResponse) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URI(java.net.URI) VdcCertListParam(com.emc.storageos.geomodel.VdcCertListParam) KeyStoreException(java.security.KeyStoreException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InvalidSoftwareVersionException(com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) UnknownHostException(java.net.UnknownHostException)

Example 32 with VirtualDataCenter

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

the class ConnectVdcTaskOp method configMerge.

private VdcConfigSyncParam configMerge(VdcPreCheckResponse operatedVdcInfo, String ipsecKey) {
    // step 2: merge the vdc config info of all sites, as the initiator, we should has all current vdc config info
    VdcConfigSyncParam vdcConfigList = new VdcConfigSyncParam();
    vdcConfigList.setVdcConfigVersion(DrUtil.newVdcConfigVersion());
    List<VdcConfig> list = vdcConfigList.getVirtualDataCenters();
    for (VirtualDataCenter vdc : getAllVdc()) {
        if (vdc.getShortId().equals(vdcInfo.getProperty(GeoServiceJob.VDC_SHORT_ID))) {
            continue;
        }
        log.info("add {} to the merged vdc config", vdc.getShortId());
        VdcConfig vdcConfig = helper.toConfigParam(vdc);
        list.add(vdcConfig);
    }
    VdcConfig operatedConfig = mergeVdcInfo(operatedVdcInfo);
    list.add(operatedConfig);
    vdcConfigList.setIpsecKey(ipsecKey);
    return vdcConfigList;
}
Also used : VdcConfigSyncParam(com.emc.storageos.geomodel.VdcConfigSyncParam) VdcConfig(com.emc.storageos.geomodel.VdcConfig) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter)

Example 33 with VirtualDataCenter

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

the class ReconnectVdcTaskOp method getWhiteList.

private List<String> getWhiteList() {
    List<String> whiteList = new ArrayList();
    List<URI> ids = dbClient.queryByType(VirtualDataCenter.class, true);
    for (URI id : ids) {
        VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, id);
        if (vdc.getConnectionStatus() == ConnectionStatus.CONNECTED) {
            Collection<String> addresses = dbClient.queryHostIPAddressesMap(vdc).values();
            whiteList.addAll(addresses);
        }
    }
    return whiteList;
}
Also used : ArrayList(java.util.ArrayList) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 34 with VirtualDataCenter

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

the class UpdateVdcTaskOp method preCheck.

private VdcPreCheckResponse preCheck() {
    log.info("Starting precheck on vdc update ...");
    // avoid to send preCheck from v2.3 or higher to v2.2 v2.1, v2.0
    if (!isRemoteVdcVersionCompatible(vdcInfo)) {
        throw GeoException.fatals.updateVdcPrecheckFail("Software version from remote vdc is lower than v2.3.");
    }
    // BZ:
    // TODO It appears that this code assumes that update node is a remote node.
    // we need to modify it to make it simpler when updated node is local.
    log.info("Send vdc precheck to remote vdc");
    VdcPreCheckResponse vdcResp = sendVdcPrecheckRequest(vdcInfo, false);
    log.info("Check vdc stable");
    // check if the cluster is stable
    URI unstable = checkAllVdcStable(false, true);
    if (unstable != null) {
        VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, unstable);
        String vdcName = (vdc != null) ? vdc.getLabel() : "";
        throw GeoException.fatals.unstableVdcFailure(vdcName);
    }
    log.info("vdc config retrieved: {}, {} {}", new Object[] { vdcResp.getApiEndpoint(), vdcResp.getHostIPv4AddressesMap(), vdcResp.getHostIPv6AddressesMap() });
    return vdcResp;
}
Also used : VdcPreCheckResponse(com.emc.storageos.geomodel.VdcPreCheckResponse) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 35 with VirtualDataCenter

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

the class VdcControllerTest method newVdcForAdding.

/**
 * New Vdc object for adding
 *
 * @return
 */
private VirtualDataCenter newVdcForAdding(String shortId) {
    VirtualDataCenter vdc = new VirtualDataCenter();
    URI vdcId = URIUtil.createVirtualDataCenterId(shortId);
    String vdcShortId = shortId;
    vdc.setShortId(vdcShortId);
    vdc.setId(vdcId);
    vdc.setVersion(2L);
    vdc.setLocal(false);
    vdc.setApiEndpoint("127.0.0.2");
    vdc.setHostCount(1);
    vdc.setConnectionStatus(VirtualDataCenter.ConnectionStatus.CONNECTING);
    vdc.setRepStatus(VirtualDataCenter.GeoReplicationStatus.REP_NONE);
    vdc.setCertificateChain(TEST_CERT);
    return vdc;
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

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