Search in sources :

Example 6 with VdcVersion

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

the class SchemaUtil method insertOrUpdateVdcVersion.

public void insertOrUpdateVdcVersion(final DbClient dbClient, boolean update) {
    String dbFullVersion = this._service.getVersion();
    String[] parts = StringUtils.split(dbFullVersion, DbConfigConstants.VERSION_PART_SEPERATOR);
    String version = parts[0] + "." + parts[1];
    URI vdcId = VdcUtil.getLocalVdc().getId();
    List<URI> vdcVersionIds = dbClient.queryByType(VdcVersion.class, true);
    List<VdcVersion> vdcVersions = dbClient.queryObject(VdcVersion.class, vdcVersionIds);
    VdcVersion vdcVersion = getVdcVersion(vdcVersions, vdcId);
    if (vdcVersion == null) {
        _log.info("insert new Vdc db version vdc={}, dbVersion={}", vdcId, version);
        vdcVersion = new VdcVersion();
        vdcVersion.setId(URIUtil.createId(VdcVersion.class));
        vdcVersion.setVdcId(vdcId);
        vdcVersion.setVersion(version);
        dbClient.createObject(vdcVersion);
    } else {
        _log.info("Skip inserting because Vdc version exists for vdc={}, dbVersion={}", vdcId, version);
    }
    if (update && !vdcVersion.getVersion().equals(version)) {
        _log.info("update Vdc db version vdc={} to dbVersion={}", vdcId, version);
        vdcVersion.setVersion(version);
        dbClient.persistObject(vdcVersion);
    }
}
Also used : VdcVersion(com.emc.storageos.db.client.model.VdcVersion) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 7 with VdcVersion

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

the class GeoUpgradeVoter method hasTripleDbVersionsInFederation.

/**
 * Check if we'll have 3 geodb schema version after upgrading to give version.
 *
 * @param targetVersion target ViPR version that current instance is going to upgrade
 * @return true if there are 3 geodb schema versions
 */
private boolean hasTripleDbVersionsInFederation(String targetVersion) {
    Set<String> allSchemaVersions = new HashSet<>();
    allSchemaVersions.add(VdcUtil.getDbSchemaVersion(targetVersion));
    List<URI> vdcIds = dbClient.queryByType(VirtualDataCenter.class, true);
    List<URI> vdcVersionIds = dbClient.queryByType(VdcVersion.class, true);
    List<VdcVersion> vdcVersions = dbClient.queryObject(VdcVersion.class, vdcVersionIds);
    Map<URI, VdcVersion> vdcIdVdcVersionMap = new HashMap<>();
    for (VdcVersion geoVersion : vdcVersions) {
        vdcIdVdcVersionMap.put(geoVersion.getVdcId(), geoVersion);
    }
    for (URI vdcId : vdcIds) {
        if (vdcIdVdcVersionMap.containsKey(vdcId)) {
            String schemaVersion = vdcIdVdcVersionMap.get(vdcId).getVersion();
            log.info("Get db schema version {} on {}", schemaVersion, vdcId);
            allSchemaVersions.add(schemaVersion);
        } else {
            log.info("Can not get db schema version on {}, will use default version instead", vdcId);
            allSchemaVersions.add(DbConfigConstants.DEFAULT_VDC_DB_VERSION);
        }
    }
    log.info("Current geodb schema versions in federation {}", allSchemaVersions);
    return allSchemaVersions.size() > 2;
}
Also used : HashMap(java.util.HashMap) VdcVersion(com.emc.storageos.db.client.model.VdcVersion) URI(java.net.URI) HashSet(java.util.HashSet)

Example 8 with VdcVersion

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

the class ConnectVdcTaskOp method hasTripleVdcVersionsInFederation.

/**
 * Check if we'll have 3 vdc versions after adding the vdc with given version
 *
 * @param vdcResp
 * @return true if there are 3 vdc versions
 */
private boolean hasTripleVdcVersionsInFederation(VdcPreCheckResponse vdcResp) {
    Set<String> allVersions = new HashSet<>();
    allVersions.add(VdcUtil.getDbSchemaVersion(vdcResp.getSoftwareVersion()));
    List<URI> vdcIds = dbClient.queryByType(VirtualDataCenter.class, true);
    List<URI> vdcVersionIds = dbClient.queryByType(VdcVersion.class, true);
    List<VdcVersion> vdcVersions = dbClient.queryObject(VdcVersion.class, vdcVersionIds);
    Map<URI, VdcVersion> vdcIdVdcVersionMap = new HashMap<>();
    for (VdcVersion vdcVersion : vdcVersions) {
        vdcIdVdcVersionMap.put(vdcVersion.getVdcId(), vdcVersion);
    }
    for (URI vdcId : vdcIds) {
        if (vdcIdVdcVersionMap.containsKey(vdcId)) {
            String schemaVersion = vdcIdVdcVersionMap.get(vdcId).getVersion();
            log.info("Get vdc version {} on {}", schemaVersion, vdcId);
            allVersions.add(schemaVersion);
        } else {
            log.info("Can not get vdc version on {}, will use default version instead", vdcId);
            allVersions.add(DbConfigConstants.DEFAULT_VDC_DB_VERSION);
        }
    }
    log.info("Current vdc versions in federation {}", allVersions);
    boolean hasTriple = allVersions.size() > 2;
    if (hasTriple) {
        log.error("Not allowed to have three different vdc versions in a federation.");
    }
    return hasTriple;
}
Also used : HashMap(java.util.HashMap) VdcVersion(com.emc.storageos.db.client.model.VdcVersion) URI(java.net.URI) HashSet(java.util.HashSet)

Example 9 with VdcVersion

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

the class RemoveVdcTaskOp method removeVdcVersion.

private void removeVdcVersion(VirtualDataCenter operatedVdc) {
    List<URI> vdcVersionIds = dbClient.queryByType(VdcVersion.class, true);
    List<VdcVersion> vdcVersions = dbClient.queryObject(VdcVersion.class, vdcVersionIds);
    for (VdcVersion vdcVersion : vdcVersions) {
        if (vdcVersion.getVdcId().equals(operatedVdc.getId())) {
            log.info("The VdcVersion record {} will be removed.", vdcVersion);
            dbClient.markForDeletion(vdcVersion);
            return;
        }
    }
}
Also used : VdcVersion(com.emc.storageos.db.client.model.VdcVersion) URI(java.net.URI)

Aggregations

VdcVersion (com.emc.storageos.db.client.model.VdcVersion)9 URI (java.net.URI)9 DbClient (com.emc.storageos.db.client.DbClient)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 NamedURI (com.emc.storageos.db.client.model.NamedURI)1