Search in sources :

Example 1 with GeoException

use of com.emc.storageos.security.geo.exceptions.GeoException in project coprhd-controller by CoprHD.

the class AbstractVdcTaskOp method isAllConnectedVdcReachableWith.

/**
 * Make sure all the connected(the status is connected, not the connectedVdc instance in this class ) vdc is
 * reachable by the targetVdc, there are two usages here:
 * 1. verify if the operatedVdc is back online and reachble with other connected vdcs,
 * 2. verify current vdc is reachable with other connected vdcs.
 */
protected boolean isAllConnectedVdcReachableWith(VirtualDataCenter targetVdc) {
    log.info("Checking to see if the vdc {} is reachable with other connected VDCs", targetVdc.getShortId());
    // Go through the connected list
    for (VirtualDataCenter vdc : connectedVdc) {
        // Don't need to check if the target vdc is reachable with itself
        if (vdc.getId().equals(targetVdc.getId())) {
            continue;
        }
        VdcNodeCheckResponse resp = null;
        List<VirtualDataCenter> vdcs = new ArrayList(1);
        vdcs.add(targetVdc);
        try {
            // vdcResp = sendVdcCheckRequest(vdc, operatedVdc);
            resp = helper.sendVdcNodeCheckRequest(vdc, vdcs);
            if (!resp.isNodesReachable()) {
                log.error("the vdc {} can not be reached by target Vdc {}", vdc.getShortId(), targetVdc.getShortId());
                errMsg = String.format("The Vdc %s can not be reached by target Vdc %s", vdc.getId().toString(), targetVdc.getId().toString());
                return false;
            }
        } catch (GeoException e) {
            errMsg = e.getMessage();
            return false;
        } catch (IllegalStateException e) {
            errMsg = e.getMessage();
            return false;
        }
    }
    return true;
}
Also used : VdcNodeCheckResponse(com.emc.storageos.geomodel.VdcNodeCheckResponse) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) FatalGeoException(com.emc.storageos.security.geo.exceptions.FatalGeoException) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) ArrayList(java.util.ArrayList)

Example 2 with GeoException

use of com.emc.storageos.security.geo.exceptions.GeoException 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 GeoException

use of com.emc.storageos.security.geo.exceptions.GeoException 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)

Example 4 with GeoException

use of com.emc.storageos.security.geo.exceptions.GeoException in project coprhd-controller by CoprHD.

the class AbstractVdcTaskOp method handle.

public void handle() {
    ServiceCoded coded = null;
    try {
        process();
        success();
    } catch (GeoException e) {
        coded = ServiceError.buildServiceError(e.getServiceCode(), e.getMessage());
        fail(coded);
        throw e;
    } catch (Exception e) {
        log.error("Vdc task failed e=", e);
        String err = "An unexpected error happens:" + e;
        coded = ServiceError.buildServiceError(ServiceCode.GEOSVC_INTERNAL_ERROR, err);
        fail(coded);
        throw e;
    }
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) FatalGeoException(com.emc.storageos.security.geo.exceptions.FatalGeoException) KeyStoreException(java.security.KeyStoreException) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) CertificateException(java.security.cert.CertificateException) FatalGeoException(com.emc.storageos.security.geo.exceptions.FatalGeoException)

Aggregations

GeoException (com.emc.storageos.security.geo.exceptions.GeoException)4 VirtualDataCenter (com.emc.storageos.db.client.model.VirtualDataCenter)2 VdcConfigSyncParam (com.emc.storageos.geomodel.VdcConfigSyncParam)2 VdcPreCheckResponse (com.emc.storageos.geomodel.VdcPreCheckResponse)2 FatalGeoException (com.emc.storageos.security.geo.exceptions.FatalGeoException)2 KeyStoreException (java.security.KeyStoreException)2 InvalidSoftwareVersionException (com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 VdcCertListParam (com.emc.storageos.geomodel.VdcCertListParam)1 VdcNodeCheckResponse (com.emc.storageos.geomodel.VdcNodeCheckResponse)1 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 Certificate (java.security.cert.Certificate)1 CertificateException (java.security.cert.CertificateException)1 ArrayList (java.util.ArrayList)1