Search in sources :

Example 1 with VdcPreCheckResponse

use of com.emc.storageos.geomodel.VdcPreCheckResponse in project coprhd-controller by CoprHD.

the class VdcConfigService method toVirtualDataCenterResponse.

private VdcPreCheckResponse toVirtualDataCenterResponse(VirtualDataCenter from, boolean hasData, SoftwareVersion remoteSoftVer, SoftwareVersion localSoftVer) {
    if (from == null) {
        return null;
    }
    Site activeSite = drUtil.getActiveSite(from.getShortId());
    VdcPreCheckResponse to = new VdcPreCheckResponse();
    to.setId(from.getId());
    to.setConnectionStatus(from.getConnectionStatus().name());
    to.setVersion(from.getVersion());
    to.setShortId(from.getShortId());
    to.setHostCount(activeSite.getNodeCount());
    StringMap ipv4Addr = new StringMap();
    ipv4Addr.putAll(activeSite.getHostIPv4AddressMap());
    to.setHostIPv4AddressesMap(ipv4Addr);
    StringMap ipv6Addr = new StringMap();
    ipv6Addr.putAll(activeSite.getHostIPv6AddressMap());
    to.setHostIPv6AddressesMap(ipv6Addr);
    to.setName(from.getLabel());
    to.setDescription(from.getDescription());
    to.setApiEndpoint(activeSite.getVipEndPoint());
    to.setSecretKey(from.getSecretKey());
    to.setHasData(hasData);
    to.setSoftwareVersion(localSoftVer.toString());
    boolean compatible = false;
    if (remoteSoftVer != null) {
        compatible = helper.isCompatibleVersion(remoteSoftVer);
    }
    to.setCompatible(compatible);
    boolean clusterStable = isClusterStable();
    to.setClusterStable(clusterStable);
    log.info("current cluster stable {}", clusterStable);
    to.setActiveSiteId(activeSite.getUuid());
    return to;
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) StringMap(com.emc.storageos.db.client.model.StringMap) VdcPreCheckResponse(com.emc.storageos.geomodel.VdcPreCheckResponse)

Example 2 with VdcPreCheckResponse

use of com.emc.storageos.geomodel.VdcPreCheckResponse 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 3 with VdcPreCheckResponse

use of com.emc.storageos.geomodel.VdcPreCheckResponse 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 4 with VdcPreCheckResponse

use of com.emc.storageos.geomodel.VdcPreCheckResponse in project coprhd-controller by CoprHD.

the class ConnectVdcTaskOp method preCheck.

/**
 * Check whether geo could accept the new vdc or not
 */
private VdcPreCheckResponse preCheck() {
    log.info("Starting precheck on vdc connect ...");
    // avoid to send preCheck from v2.3 or higher to v2.2 v2.1, v2.0
    if (!isRemoteVdcVersionCompatible(vdcInfo)) {
        throw GeoException.fatals.connectVdcPrecheckFail(myVdcId, "Software version from remote vdc is lower than v2.3.");
    }
    log.info("Send vdc precheck to remote vdc");
    // step 1: 2 way communication to verify if link should be permitted
    VdcPreCheckResponse vdcResp = sendVdcPrecheckRequest(vdcInfo, true);
    log.info("Check VIP of remote vdc is used as the ApiEndpoint");
    // verify if node IP address is used as the ApiEndpoint
    String virtualIP = vdcInfo.getProperty(GeoServiceJob.VDC_API_ENDPOINT);
    if (!InetAddresses.isInetAddress(virtualIP)) {
        // FQDN used
        log.info("FQDN or hostname used: {}", virtualIP);
        try {
            virtualIP = InetAddress.getByName(vdcInfo.getProperty(GeoServiceJob.VDC_API_ENDPOINT)).getHostAddress();
            // replace with real IP
            vdcInfo.setProperty(GeoServiceJob.VDC_API_ENDPOINT, virtualIP);
            log.info("virtual ip of new vdc {}", virtualIP);
        } catch (UnknownHostException e) {
            throw GeoException.fatals.invalidFQDNEndPoint(vdcInfo.getProperty(GeoServiceJob.VDC_NAME), virtualIP);
        }
    }
    if (vdcResp.getHostIPv4AddressesMap().containsValue(virtualIP) || vdcResp.getHostIPv6AddressesMap().containsValue(virtualIP)) {
        throw GeoException.fatals.wrongIPSpecification(vdcInfo.getProperty(GeoServiceJob.VDC_NAME));
    }
    log.info("Check vdc stable");
    // check if the cluster is stable
    if (!vdcResp.isClusterStable()) {
        throw GeoException.fatals.unstableVdcFailure(vdcInfo.getProperty(GeoServiceJob.VDC_NAME));
    }
    URI unstable = checkAllVdcStable(false, false);
    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: vip={}, IPv4Addresses={}, IPv6Addresses={} isHasData={}", new Object[] { vdcResp.getApiEndpoint(), vdcResp.getHostIPv4AddressesMap(), vdcResp.getHostIPv6AddressesMap(), vdcResp.isHasData() });
    if (vdcResp.isHasData()) {
        throw GeoException.fatals.remoteVDCContainData();
    }
    // verify the software version compatibility
    if (!isGeoCompatible(vdcResp)) {
        throw GeoException.fatals.remoteVDCInLowerVersion();
    }
    if (hasTripleVdcVersionsInFederation(vdcResp)) {
        throw GeoException.fatals.hasTripleVDCVersionsInFederation();
    }
    if (!isCompatibleVersion(vdcResp)) {
        throw GeoException.fatals.remoteVDCIncompatibleVersion();
    }
    if (!checkNodeConnectivity(vdcResp)) {
        throw GeoException.fatals.failedToCheckConnectivity(errMsg);
    }
    return vdcResp;
}
Also used : VdcPreCheckResponse(com.emc.storageos.geomodel.VdcPreCheckResponse) UnknownHostException(java.net.UnknownHostException) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 5 with VdcPreCheckResponse

use of com.emc.storageos.geomodel.VdcPreCheckResponse in project coprhd-controller by CoprHD.

the class UpdateVdcTaskOp method checkAndSync.

/**
 * Precheck if vdc update is permitted, then sync the vdc config to all sites to
 * update an existing vdc
 */
public void checkAndSync() {
    lockHelper.acquire(operatedVdc.getShortId());
    geoClientCache.clearCache();
    loadVdcInfo();
    if (StringUtils.isNotEmpty(updateInfo.getProperty(GeoServiceJob.VDC_CERTIFICATE_CHAIN)) && (operatedVdc.getId().compareTo(myVdc.getId()) != 0)) {
        String errMsg = "could not update key certchain from remote VDC.";
        log.error(errMsg);
        throw GeoException.fatals.updateVdcPrecheckFail(errMsg);
    }
    VdcPreCheckResponse operatedVdcInfo = preCheck();
    GeoServiceHelper.backupOperationVdc(dbClient, GeoServiceJob.JobType.VDC_UPDATE_JOB, operatedVdcInfo.getId(), params.toString());
    failedVdcStatus = ConnectionStatus.UPDATE_FAILED;
    updateOperatedVdc();
    operatedVdc.setConnectionStatus(VirtualDataCenter.ConnectionStatus.UPDATING);
    dbClient.updateAndReindexObject(operatedVdc);
    loadVdcInfo();
    VdcConfigSyncParam mergedVdcInfo = mergeConfig(operatedVdcInfo);
    if (mergedVdcInfo == null) {
        log.error("merge the vdc config of all sites failed");
        throw GeoException.fatals.mergeConfigFail();
    }
    try {
        syncConfig(mergedVdcInfo);
    } catch (GeoException ex) {
        throw ex;
    } catch (Exception e) {
        log.error("Failed to sync vdc config to all sites : {}", e);
        throw GeoException.fatals.syncConfigFail(e);
    }
    String cert = updateInfo.getProperty(GeoServiceJob.VDC_CERTIFICATE_CHAIN);
    if (StringUtils.isNotEmpty(cert)) {
        VdcCertListParam certListParam = genCertOperationParam(VdcCertListParam.CMD_UPDATE_CERT);
        syncCerts(VdcCertListParam.CMD_UPDATE_CERT, certListParam);
        // set key and cert in local keystore
        Boolean selfsigned = (Boolean) params.get(1);
        byte[] key = (byte[]) params.get(2);
        Certificate[] certchain = (Certificate[]) params.get(3);
        helper.setKeyCertchain(selfsigned, key, certchain);
    }
    // lock is released in error handling code if an exception is thrown before we get
    // here. note that since there is no post processing for update, there is no way
    // to know if the sync operation is complete; lock must be released here before
    // sync is done.
    lockHelper.release(operatedVdc.getShortId());
}
Also used : VdcConfigSyncParam(com.emc.storageos.geomodel.VdcConfigSyncParam) VdcPreCheckResponse(com.emc.storageos.geomodel.VdcPreCheckResponse) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) Certificate(java.security.cert.Certificate)

Aggregations

VdcPreCheckResponse (com.emc.storageos.geomodel.VdcPreCheckResponse)5 VirtualDataCenter (com.emc.storageos.db.client.model.VirtualDataCenter)3 URI (java.net.URI)3 VdcConfigSyncParam (com.emc.storageos.geomodel.VdcConfigSyncParam)2 GeoException (com.emc.storageos.security.geo.exceptions.GeoException)2 UnknownHostException (java.net.UnknownHostException)2 Site (com.emc.storageos.coordinator.client.model.Site)1 InvalidSoftwareVersionException (com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException)1 StringMap (com.emc.storageos.db.client.model.StringMap)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 VdcCertListParam (com.emc.storageos.geomodel.VdcCertListParam)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 KeyStoreException (java.security.KeyStoreException)1 Certificate (java.security.cert.Certificate)1