Search in sources :

Example 1 with VdcVersion

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

the class VdcUtilTest method shouldReturnDefaultVersionIfNoGeoVersion.

@Test
public void shouldReturnDefaultVersionIfNoGeoVersion() {
    DbClient dbClientMock = EasyMock.createMock(DbClient.class);
    EasyMock.expect(dbClientMock.queryByType(VdcVersion.class, true)).andReturn(new ArrayList<URI>());
    EasyMock.expect(dbClientMock.queryObject(VdcVersion.class, new ArrayList<URI>())).andReturn(new ArrayList<VdcVersion>());
    EasyMock.expect(dbClientMock.queryByType(VirtualDataCenter.class, true)).andReturn(new ArrayList<URI>());
    EasyMock.replay(dbClientMock);
    VdcUtil.setDbClient(dbClientMock);
    String minialVdcVersion = VdcUtil.getMinimalVdcVersion();
    String expectedVdcVersion = DbConfigConstants.DEFAULT_VDC_DB_VERSION;
    Assert.assertEquals(expectedVdcVersion, minialVdcVersion);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) VdcVersion(com.emc.storageos.db.client.model.VdcVersion) URI(java.net.URI) Test(org.junit.Test)

Example 2 with VdcVersion

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

the class VdcUtilTest method shouldReturnDefaultVersionIfMissVdcVersion.

@Test
public void shouldReturnDefaultVersionIfMissVdcVersion() {
    List<VdcVersion> geoVersions = new ArrayList<VdcVersion>();
    List<URI> vdcIds = new ArrayList<URI>();
    geoVersions.add(VDC2_GEO_VERSION);
    vdcIds.add(VDC1_ID);
    vdcIds.add(VDC2_ID);
    DbClient dbClientMock = EasyMock.createMock(DbClient.class);
    EasyMock.expect(dbClientMock.queryByType(VdcVersion.class, true)).andReturn(new ArrayList<URI>());
    EasyMock.expect(dbClientMock.queryObject(VdcVersion.class, new ArrayList<URI>())).andReturn(geoVersions);
    EasyMock.expect(dbClientMock.queryByType(VirtualDataCenter.class, true)).andReturn(vdcIds);
    EasyMock.replay(dbClientMock);
    VdcUtil.setDbClient(dbClientMock);
    String minialVdcVersion = VdcUtil.getMinimalVdcVersion();
    String expectedVdcVersion = DbConfigConstants.DEFAULT_VDC_DB_VERSION;
    Assert.assertEquals(expectedVdcVersion, minialVdcVersion);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) ArrayList(java.util.ArrayList) VdcVersion(com.emc.storageos.db.client.model.VdcVersion) URI(java.net.URI) Test(org.junit.Test)

Example 3 with VdcVersion

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

the class VdcUtil method checkGeoCompatibleOfOtherVdcs.

/**
 * Check if geo version of all other vdcs(excluding local vdc) are equal to or higher than target version
 *
 * @param targetVersion
 * @return
 */
public static boolean checkGeoCompatibleOfOtherVdcs(String targetVersion) {
    URI localVdcId = getLocalVdc().getId();
    List<URI> geoVerIds = dbClient.queryByType(VdcVersion.class, true);
    List<VdcVersion> geoVersions = dbClient.queryObject(VdcVersion.class, geoVerIds);
    for (VdcVersion geoVersion : geoVersions) {
        URI vdcId = geoVersion.getVdcId();
        if (vdcId.equals(localVdcId)) {
            // skip current vdc
            continue;
        }
        if (VdcVersionComparator.compare(geoVersion.getVersion(), targetVersion) < 0) {
            log.info("Vdc {} version is less than {}", new Object[] { vdcId, targetVersion });
            return false;
        }
    }
    return true;
}
Also used : VdcVersion(com.emc.storageos.db.client.model.VdcVersion) URI(java.net.URI)

Example 4 with VdcVersion

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

the class VdcUtil method getMinimalVdcVersion.

public static String getMinimalVdcVersion() {
    List<URI> vdcIds = getVdcIds();
    List<URI> geoVerIds = dbClient.queryByType(VdcVersion.class, true);
    List<VdcVersion> geoVersions = dbClient.queryObject(VdcVersion.class, geoVerIds);
    if (!hasAnyGeoVersion(geoVersions)) {
        log.info("GeoVersion doesn't exist, return default version");
        return DbConfigConstants.DEFAULT_VDC_DB_VERSION;
    }
    if (missVersionFor(vdcIds, geoVersions)) {
        log.info("GeoVersion not exist for vdcs, return default version");
        return DbConfigConstants.DEFAULT_VDC_DB_VERSION;
    }
    String minimalVersion = null;
    for (VdcVersion geoVersion : geoVersions) {
        if ((minimalVersion == null) || (VdcVersionComparator.compare(minimalVersion, geoVersion.getVersion()) > 0)) {
            minimalVersion = geoVersion.getVersion();
        }
    }
    log.info("minimal Geo version {}", minimalVersion);
    return minimalVersion;
}
Also used : VdcVersion(com.emc.storageos.db.client.model.VdcVersion) URI(java.net.URI)

Example 5 with VdcVersion

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

the class VdcUtilTest method shouldReturnMinimalVersionInVdcVersions.

@Test
public void shouldReturnMinimalVersionInVdcVersions() {
    List<VdcVersion> geoVersions = new ArrayList<VdcVersion>();
    List<URI> vdcIds = new ArrayList<URI>();
    geoVersions.add(VDC1_GEO_VERSION);
    geoVersions.add(VDC2_GEO_VERSION);
    geoVersions.add(VDC3_GEO_VERSION);
    vdcIds.add(VDC1_ID);
    vdcIds.add(VDC2_ID);
    vdcIds.add(VDC3_ID);
    DbClient dbClientMock = EasyMock.createMock(DbClient.class);
    EasyMock.expect(dbClientMock.queryByType(VdcVersion.class, true)).andReturn(new ArrayList<URI>());
    EasyMock.expect(dbClientMock.queryObject(VdcVersion.class, new ArrayList<URI>())).andReturn(geoVersions);
    EasyMock.expect(dbClientMock.queryByType(VirtualDataCenter.class, true)).andReturn(vdcIds);
    EasyMock.replay(dbClientMock);
    VdcUtil.setDbClient(dbClientMock);
    String minialVdcVersion = VdcUtil.getMinimalVdcVersion();
    String expectedVdcVersion = DbConfigConstants.DEFAULT_VDC_DB_VERSION;
    Assert.assertEquals(expectedVdcVersion, minialVdcVersion);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) ArrayList(java.util.ArrayList) VdcVersion(com.emc.storageos.db.client.model.VdcVersion) URI(java.net.URI) Test(org.junit.Test)

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