Search in sources :

Example 76 with VirtualDataCenter

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

the class VdcConfigHelper method mergeVdcConfig.

private void mergeVdcConfig(VdcConfig targetVdc, boolean isRecover) {
    VirtualDataCenter srcVdc = dbClient.queryObject(VirtualDataCenter.class, targetVdc.getId());
    if (!isRecover && targetVdc.getVersion() < srcVdc.getVersion()) {
        log.info("VDC config for {} is older than that from the local db and is " + "ignored.", targetVdc.getId());
        return;
    }
    boolean isChanged = false;
    log.info("mergeVdcConfig - Vdc connection status {}, new status {}", srcVdc.getConnectionStatus(), targetVdc.getConnectionStatus());
    if (!isEqual(srcVdc.getConnectionStatus(), targetVdc.getConnectionStatus())) {
        isChanged = true;
        if (srcVdc.getLocal()) {
            log.warn("The local VDC connection status changes from {} to {} " + "according to remote VDC config.", srcVdc.getConnectionStatus(), targetVdc.getConnectionStatus());
        }
        if (targetVdc.getConnectionStatus() != null) {
            srcVdc.setConnectionStatus(Enum.valueOf(ConnectionStatus.class, targetVdc.getConnectionStatus()));
        }
    }
    if (!isEqual(srcVdc.getRepStatus(), targetVdc.getRepStatus())) {
        isChanged = true;
        if (srcVdc.getLocal()) {
            log.warn("The local VDC rep status changes from {} to {} " + "according to remote VDC config.", srcVdc.getRepStatus(), targetVdc.getRepStatus());
        }
        if (targetVdc.getRepStatus() != null) {
            srcVdc.setRepStatus(Enum.valueOf(GeoReplicationStatus.class, targetVdc.getRepStatus()));
        }
    }
    if (!isEqual(srcVdc.getVersion(), targetVdc.getVersion())) {
        isChanged = true;
        if (srcVdc.getLocal()) {
            log.warn("The local VDC version changes from {} to {} according to " + "remote VDC config.", srcVdc.getVersion(), targetVdc.getVersion());
        }
        srcVdc.setVersion(targetVdc.getVersion());
    }
    if (!isEqual(srcVdc.getLabel(), targetVdc.getName())) {
        isChanged = true;
        if (srcVdc.getLocal()) {
            log.warn("The local VDC label changes from {} to {} according to remote " + " VDC config.", srcVdc.getLabel(), targetVdc.getName());
        }
        srcVdc.setLabel(targetVdc.getName());
    }
    if (!isEqual(srcVdc.getDescription(), targetVdc.getDescription())) {
        isChanged = true;
        if (srcVdc.getLocal()) {
            log.warn("The local VDC description changes from {} to {} according to " + "remote VDC config.", srcVdc.getDescription(), targetVdc.getDescription());
        }
        srcVdc.setDescription(targetVdc.getDescription());
    }
    if (!isEqual(srcVdc.getApiEndpoint(), targetVdc.getApiEndpoint())) {
        isChanged = true;
        if (srcVdc.getLocal()) {
            log.warn("The local VDC API endpoint changes from {} to {} according to " + "remote VDC config.", srcVdc.getApiEndpoint(), targetVdc.getApiEndpoint());
        }
        srcVdc.setApiEndpoint(targetVdc.getApiEndpoint());
    }
    if (!isEqual(srcVdc.getSecretKey(), targetVdc.getSecretKey())) {
        srcVdc.setSecretKey(targetVdc.getSecretKey());
        isChanged = true;
        if (srcVdc.getLocal()) {
            log.warn("The local VDC security key changes from {} to {} according to " + "remote VDC config.", srcVdc.getSecretKey(), targetVdc.getSecretKey());
        }
    }
    if (!isEqual(srcVdc.getShortId(), targetVdc.getShortId())) {
        isChanged = true;
        log.warn("Short id of VDC {} changes from {} to {} according to remote VDC " + "config.", new Object[] { srcVdc.getId(), srcVdc.getShortId(), targetVdc.getShortId() });
        srcVdc.setShortId(targetVdc.getShortId());
    }
    if (!isEqual(srcVdc.getGeoCommandEndpoint(), targetVdc.getGeoCommandEndpoint())) {
        isChanged = true;
        log.warn("GeoCommandEndpoint of VDC {} changes from {} to {} according to remote VDC " + "config.", new Object[] { srcVdc.getGeoCommandEndpoint(), srcVdc.getGeoCommandEndpoint(), targetVdc.getGeoCommandEndpoint() });
        srcVdc.setGeoCommandEndpoint(targetVdc.getGeoCommandEndpoint());
    }
    if (!isEqual(srcVdc.getGeoDataEndpoint(), targetVdc.getGeoDataEndpoint())) {
        isChanged = true;
        log.warn("GeoDataEndpoint of VDC {} changes from {} to {} according to remote VDC " + "config.", new Object[] { srcVdc.getGeoDataEndpoint(), srcVdc.getGeoDataEndpoint(), targetVdc.getGeoDataEndpoint() });
        srcVdc.setGeoDataEndpoint(targetVdc.getGeoDataEndpoint());
    }
    // If this vdc is isolated, should then reset repstatus to rep_none
    log.info("Checking if Vdc {} is isolated ...{}", targetVdc.getId(), targetVdc.getConnectionStatus());
    if (targetVdc.getConnectionStatus().equals(ConnectionStatus.ISOLATED.toString())) {
        log.info("Vdc {} is isolated, setting georep state to not replicated.", targetVdc.getShortId());
        isChanged = true;
        srcVdc.setRepStatus(GeoReplicationStatus.REP_NONE);
    }
    if (isChanged) {
        dbClient.updateAndReindexObject(srcVdc);
    }
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) GeoReplicationStatus(com.emc.storageos.db.client.model.VirtualDataCenter.GeoReplicationStatus) ConnectionStatus(com.emc.storageos.db.client.model.VirtualDataCenter.ConnectionStatus)

Example 77 with VirtualDataCenter

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

the class VdcConfigHelper method syncVdcConfig.

public void syncVdcConfig(List<VdcConfig> newVdcConfigList, String assignedVdcId, boolean isRecover, Long vdcConfigVersion, String ipsecKey) {
    boolean vdcConfigChanged = false;
    // query existing vdc list from db
    // The new queryByType method returns an iterative list, convert it to a "real"
    // list first
    List<URI> vdcIdList = new ArrayList<URI>();
    for (URI vdcId : dbClient.queryByType(VirtualDataCenter.class, true)) {
        vdcIdList.add(vdcId);
    }
    // vdc that are going to be removed from local db
    for (VdcConfig config : newVdcConfigList) {
        if (vdcIdList.contains(config.getId())) {
            vdcIdList.remove(config.getId());
            mergeVdcConfig(config, isRecover);
        } else {
            // not contains in vdcIdList - it is a new vdc and we should insert to db
            VirtualDataCenter newVdc = fromConfigParam(config);
            if (config.getId().toString().equals(assignedVdcId)) {
                newVdc.setLocal(true);
            }
            dbClient.createObject(newVdc);
            if (newVdc.getLocal()) {
                VdcUtil.invalidateVdcUrnCache();
            }
            createVdcConfigInZk(config, ipsecKey);
            vdcConfigChanged = true;
            if (newVdc.getLocal()) {
                drUtil.setLocalVdcShortId(newVdc.getShortId());
            }
        }
    }
    // check vdc that are going to be removed
    ArrayList<String> obsoletePeers = new ArrayList<String>();
    for (URI removeVdcId : vdcIdList) {
        log.warn("vdc config {} is being removed", removeVdcId);
        VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, removeVdcId);
        ConnectionStatus connStatus = vdc.getConnectionStatus();
        if (!isRecover && connStatus.equals(ConnectionStatus.CONNECT_FAILED)) {
            log.info("Ignore vdc record {} with status {}", removeVdcId, connStatus);
            continue;
        }
        dbClient.markForDeletion(vdc);
        Map<String, String> addressesMap = dbClient.queryHostIPAddressesMap(vdc);
        if (!addressesMap.isEmpty()) {
            // obsolete peers ip in cassandra system table
            obsoletePeers.addAll(addressesMap.values());
            log.info("add {} peers to obsolete list", addressesMap.size());
        }
        dbClient.removeVdcNodesFromBlacklist(vdc);
        deleteVdcConfigFromZk(vdc);
        vdcConfigChanged = true;
    }
    if (!obsoletePeers.isEmpty()) {
        // update peer ip to ZK so that geodbsvc could get it
        notifyDbSvcWithObsoleteCassandraPeers(Constants.GEODBSVC_NAME, obsoletePeers);
        log.info("notify geodbsvc with {} obsolete cassandra peers", obsoletePeers.size());
    }
    if (assignedVdcId != null) {
        // Persist a flag to notify geodbsvc on all the nodes in the current vdc
        log.info("reset db needed, set the flag for all db to look it up");
        updateDbSvcConfig(Constants.GEODBSVC_NAME, Constants.REINIT_DB, String.valueOf(true));
    }
    if (vdcConfigChanged) {
        String action = SiteInfo.GEO_OP_CONFIG_CHANGE;
        // loses connection with other nodes
        if (assignedVdcId != null) {
            action = SiteInfo.IPSEC_OP_ROTATE_KEY;
        }
        triggerVdcConfigUpdate(vdcConfigVersion, action);
    }
}
Also used : VdcConfig(com.emc.storageos.geomodel.VdcConfig) ArrayList(java.util.ArrayList) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) ConnectionStatus(com.emc.storageos.db.client.model.VirtualDataCenter.ConnectionStatus) URI(java.net.URI)

Example 78 with VirtualDataCenter

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

the class AbstractVdcTaskOp method loadVdcInfo.

protected void loadVdcInfo() {
    toBeSyncedVdc.clear();
    allVdc.clear();
    connectedVdc.clear();
    List<URI> vdcIdIter = dbClient.queryByType(VirtualDataCenter.class, true);
    boolean isolated = false;
    List<VirtualDataCenter> allOtherVdc = new ArrayList<>();
    for (URI vdcId : vdcIdIter) {
        VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, vdcId);
        if (vdc.getLocal()) {
            myVdc = vdc;
            myVdcId = myVdc.getId().toString();
            // self connected
            connectedVdc.add(myVdc);
            allVdc.add(myVdc);
            if ((myVdc.getConnectionStatus() == VirtualDataCenter.ConnectionStatus.ISOLATED) || (myVdc.getRepStatus() == VirtualDataCenter.GeoReplicationStatus.REP_NONE)) {
                isolated = true;
            }
        } else {
            allOtherVdc.add(vdc);
        }
    }
    if (!isolated) {
        for (VirtualDataCenter vdc : allOtherVdc) {
            if (vdc.getRepStatus() != VirtualDataCenter.GeoReplicationStatus.REP_NONE) {
                allVdc.add(vdc);
                if (vdc.getConnectionStatus() != VirtualDataCenter.ConnectionStatus.DISCONNECTED) {
                    connectedVdc.add(vdc);
                    toBeSyncedVdc.add(vdc);
                }
            }
        }
    }
    if (operatedVdc != null && !operatedVdc.getId().equals(myVdc.getId()) && !doesContainOperatedVdc()) {
        // toBeSyncedVdc does not include local
        toBeSyncedVdc.add(operatedVdc);
    }
    log.info("toBeSyncedVdc:{} connectedVdc: {}", toBeSyncedVdc, connectedVdc);
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 79 with VirtualDataCenter

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

the class AbstractVdcTaskOp method syncCerts.

protected void syncCerts(String cmd, VdcCertListParam certListParam) {
    // loop all VDCs with latest vdcs certs info
    // geoclient shall responsible to retry all retryable errors, we have no need retry here
    log.info("syncing vdcs certs to all sites ...");
    List<VirtualDataCenter> vdcList = getToBeSyncedVdc();
    for (VirtualDataCenter vdc : vdcList) {
        log.info("Loop {}:{} to sync the latest vdc cert info", vdc.getShortId(), vdc.getApiEndpoint());
        syncCertForSingleVdc(certListParam, vdc);
    }
    log.info("Finished sync vdc certs to all sites.");
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter)

Example 80 with VirtualDataCenter

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

the class AbstractVdcTaskOp method genCertListParam.

protected VdcCertListParam genCertListParam(String cmd) {
    log.info("generating certs sync parameter ...");
    VdcCertListParam certsParam = genCertOperationParam(cmd);
    // add certs of the current existing VDCs
    List<VdcCertParam> certs = certsParam.getVdcCerts();
    List<VirtualDataCenter> vdcList = getAllVdc();
    for (VirtualDataCenter vdc : vdcList) {
        if (!vdc.getId().equals(operatedVdc.getId())) {
            log.info("adding cert from vdc {} into sync param...", vdc.getId().toString());
            VdcCertParam certParam = new VdcCertParam();
            certParam.setVdcId(vdc.getId());
            try {
                Certificate cert = null;
                if (myVdc.getId().compareTo(vdc.getId()) == 0) {
                    log.info("it is local vdc {}", vdc.getId().toString());
                    Certificate[] certChain = null;
                    certChain = keystore.getCertificateChain(KeystoreEngine.ViPR_KEY_AND_CERTIFICATE_ALIAS);
                    cert = certChain[0];
                } else {
                    log.info("it is a remote vdc {}", vdc.getId().toString());
                    cert = keystore.getCertificate(vdc.getId().toString());
                }
                certParam.setCertificate(KeyCertificatePairGenerator.getCertificateAsString(cert));
                certs.add(certParam);
            } catch (KeyStoreException ex) {
                log.error("Failed to get key from the keyStore at VDC " + vdc.getLabel());
                throw GeoException.fatals.keyStoreFailure(vdc.getLabel(), ex);
            } catch (CertificateException ex) {
                log.error("Failed to get proper certificate on VDC " + vdc.getLabel());
                throw GeoException.fatals.connectVdcSyncCertFail(vdc.getLabel(), ex);
            }
        }
    }
    return certsParam;
}
Also used : VdcCertParam(com.emc.storageos.geomodel.VdcCertParam) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) VdcCertListParam(com.emc.storageos.geomodel.VdcCertListParam) Certificate(java.security.cert.Certificate)

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