use of com.emc.storageos.db.common.DependencyChecker in project coprhd-controller by CoprHD.
the class DbsvcTestBase method startDb.
/**
* Start embedded DB
*/
protected static void startDb(String currentVersion, String targetVersion, String extraModelsPkg, DataObjectScanner scanner, boolean createMockHandler) throws IOException {
sourceVersion = new DbVersionInfo();
sourceVersion.setSchemaVersion(currentVersion);
DbVersionInfo targetVersionInfo = new DbVersionInfo();
targetVersionInfo.setSchemaVersion(targetVersion);
List<String> packages = new ArrayList<String>();
packages.add("com.emc.storageos.db.client.model");
packages.add("com.emc.sa.model");
if (extraModelsPkg != null) {
packages.add(extraModelsPkg);
}
String[] pkgsArray = packages.toArray(new String[packages.size()]);
service = new ServiceImpl();
service.setName("dbsvc");
service.setVersion(targetVersion);
service.setEndpoint(URI.create("thrift://localhost:9160"));
service.setId("db-standalone");
StubBeaconImpl beacon = new StubBeaconImpl(service);
if (scanner == null) {
scanner = new DataObjectScanner();
scanner.setPackages(pkgsArray);
scanner.init();
}
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("nodeaddrmap-var.xml");
CoordinatorClientInetAddressMap inetAddressMap = (CoordinatorClientInetAddressMap) ctx.getBean("inetAddessLookupMap");
if (inetAddressMap == null) {
_log.error("CoordinatorClientInetAddressMap is not initialized. Node address lookup will fail.");
}
_coordinator.setInetAddessLookupMap(inetAddressMap);
_coordinator.setDbVersionInfo(sourceVersion);
ConfigurationImpl cfg = new ConfigurationImpl();
cfg.setKind(Constants.DB_CONFIG);
cfg.setId(Constants.GLOBAL_ID);
cfg.setConfig(Constants.SCHEMA_VERSION, currentVersion);
_coordinator.persistServiceConfiguration(cfg);
statusChecker = new DbServiceStatusChecker();
statusChecker.setCoordinator(_coordinator);
statusChecker.setClusterNodeCount(1);
statusChecker.setDbVersionInfo(sourceVersion);
statusChecker.setServiceName(service.getName());
SecretKey key = null;
try {
KeyGenerator keyGenerator = null;
keyGenerator = KeyGenerator.getInstance("HmacSHA256");
key = keyGenerator.generateKey();
} catch (NoSuchAlgorithmException e) {
fail("generate key fail");
}
schemaUtil = new MockSchemaUtil();
schemaUtil.setKeyspaceName("Test");
schemaUtil.setClusterName("Test");
schemaUtil.setDataObjectScanner(scanner);
schemaUtil.setService(service);
schemaUtil.setStatusChecker(statusChecker);
schemaUtil.setCoordinator(_coordinator);
schemaUtil.setVdcShortId("datacenter1");
schemaUtil.setDrUtil(new DrUtil(_coordinator));
DbClientContext dbctx = new MockDbClientContext();
dbctx.setClusterName("Test");
dbctx.setKeyspaceName("Test");
schemaUtil.setClientContext(dbctx);
Properties props = new Properties();
props.put(DbClientImpl.DB_STAT_OPTIMIZE_DISK_SPACE, "false");
schemaUtil.setDbCommonInfo(props);
List<String> vdcHosts = new ArrayList();
vdcHosts.add("127.0.0.1");
schemaUtil.setVdcNodeList(vdcHosts);
schemaUtil.setDbCommonInfo(new java.util.Properties());
JmxServerWrapper jmx = new JmxServerWrapper();
if (_startJmx) {
jmx.setEnabled(true);
jmx.setServiceUrl("service:jmx:rmi://localhost:%d/jndi/rmi://%s:%d/jmxrmi");
jmx.setHost("127.0.0.1");
jmx.setPort(7199);
jmx.setExportPort(7200);
} else {
jmx.setEnabled(false);
}
_encryptionProvider.setCoordinator(_coordinator);
_dbClient = getDbClientBase();
_dbClient.setDbVersionInfo(targetVersionInfo);
PasswordUtils passwordUtils = new PasswordUtils();
passwordUtils.setCoordinator(_coordinator);
passwordUtils.setEncryptionProvider(_encryptionProvider);
passwordUtils.setDbClient(_dbClient);
schemaUtil.setPasswordUtils(passwordUtils);
DependencyChecker localDependencyChecker = new DependencyChecker(_dbClient, scanner);
_geoDependencyChecker = new GeoDependencyChecker(_dbClient, _coordinator, localDependencyChecker);
_dbsvc = new TestMockDbServiceImpl();
_dbsvc.setConfig("db-test.yaml");
_dbsvc.setSchemaUtil(schemaUtil);
_dbsvc.setCoordinator(_coordinator);
_dbsvc.setStatusChecker(statusChecker);
_dbsvc.setService(service);
_dbsvc.setJmxServerWrapper(jmx);
_dbsvc.setDbClient(_dbClient);
_dbsvc.setBeacon(beacon);
_dbsvc.setDbDir(dataDir);
_dbsvc.setDisableScheduledDbRepair(true);
_dbsvc.setMigrationHandler(getMigrationHandler(createMockHandler, pkgsArray));
_dbsvc.setDbMgr(new MockDbManager());
_dbsvc.start();
isDbStarted = true;
}
use of com.emc.storageos.db.common.DependencyChecker in project coprhd-controller by CoprHD.
the class GarbageCollectorTests method checkGCOnLevelN.
private void checkGCOnLevelN(int level, Class<? extends DataObject> clazz) throws Exception {
_log.info("Level {}: type: {}", level, clazz.getSimpleName());
String levelSuffix = "checkGCOnLevel" + level;
DataObject obj = clazz.newInstance();
obj.setId(URIUtil.createId(clazz));
obj.setLabel(String.format("%s:%s", clazz.getSimpleName(), levelSuffix));
if (level > 0) {
// first, create a full chain, all the way to the root
Map<Integer, List<TypeURI>> allChildren = new HashMap<Integer, List<TypeURI>>();
createChildren(clazz, obj, level, allChildren);
obj.setInactive(true);
_dbClient.createObject(obj);
_gcExecutor.runNow();
DataObject read = _dbClient.queryObject(clazz, obj.getId());
Assert.assertNotNull(read);
Assert.assertTrue(read.getInactive());
// start with deleting lowest first
for (int i = 0; i <= level; i++) {
List<TypeURI> children = allChildren.get(i);
if (!children.isEmpty()) {
for (TypeURI child : children) {
read = _dbClient.queryObject(child._type, child._uri);
read.setInactive(true);
_dbClient.updateAndReindexObject(read);
_log.info("marking inactive : {}", child._uri);
}
_gcExecutor.runNow();
for (TypeURI child : children) {
read = _dbClient.queryObject(child._type, child._uri);
Assert.assertNull(read);
}
if (i != level) {
read = _dbClient.queryObject(clazz, obj.getId());
Assert.assertNotNull(read);
}
}
}
// last level should have deleted the main object also
} else {
// no dependents
_dbClient.updateAndReindexObject(obj);
_gcExecutor.runNow();
DataObject read = _dbClient.queryObject(clazz, obj.getId());
read.setInactive(true);
_dbClient.updateAndReindexObject(read);
_gcExecutor.runNow();
}
DataObject read = _dbClient.queryObject(clazz, obj.getId());
if (read != null) {
String dep = new DependencyChecker(_dbClient, _scanner.getDependencyTracker()).checkDependencies(read.getId(), read.getClass(), false);
Assert.fail(String.format("Object with id %s is not recycled because of dependency: %s", read.getId().toString(), dep));
}
}
use of com.emc.storageos.db.common.DependencyChecker in project coprhd-controller by CoprHD.
the class DBClient method queryAndDeleteObject.
/**
* Query for a record with the given id and type, and print the contents in human readable format
*
* @param id
* @param clazz
* @param <T>
*/
private <T extends DataObject> boolean queryAndDeleteObject(URI id, Class<T> clazz, boolean force) throws Exception {
DependencyTracker dependencyTracker = null;
if (_dependencyChecker == null) {
DataObjectScanner dataObjectscanner = (DataObjectScanner) ctx.getBean("dataObjectScanner");
dependencyTracker = dataObjectscanner.getDependencyTracker();
_dependencyChecker = new DependencyChecker(_dbClient, dependencyTracker);
}
String reference = _dependencyChecker.checkDependencies(id, clazz, false);
if (reference != null) {
if (!force) {
System.err.println(String.format("Failed to delete the object %s: there are active dependencies", id));
printReferenceWhenDeletingFailed(id, clazz, dependencyTracker);
return false;
}
log.info("Force to delete object {} that has active dependencies", id);
}
T object = queryObject(id, clazz);
if (object == null) {
System.err.println(String.format("The object %s has already been deleted", id));
return false;
}
if ((object.canBeDeleted() == null) || force) {
if (object.canBeDeleted() != null) {
log.info("Force to delete object {} that can't be deleted", id);
}
_dbClient.internalRemoveObjects(object);
return true;
}
System.err.println(String.format("The object %s can't be deleted", id));
printReferenceWhenDeletingFailed(id, clazz, dependencyTracker);
return false;
}
use of com.emc.storageos.db.common.DependencyChecker in project coprhd-controller by CoprHD.
the class DbCli method queryAndDeleteObject.
/**
* Query for a record with the given id and type, and print the contents in human readable format
*
* @param id
* @param clazz
* @param <T>
*/
private <T extends DataObject> boolean queryAndDeleteObject(URI id, Class<T> clazz, boolean force) throws Exception {
if (_dependencyChecker == null) {
DependencyTracker dependencyTracker = dataObjectscanner.getDependencyTracker();
_dependencyChecker = new DependencyChecker(_dbClient, dependencyTracker);
}
if (_dependencyChecker.checkDependencies(id, clazz, false) != null) {
if (!force) {
System.out.println(String.format("Failed to delete the object %s: there are active dependencies", id));
return false;
}
log.info("Force to delete object {} that has active dependencies", id);
}
T object = queryObject(id, clazz);
if (object == null) {
System.out.println(String.format("The object %s has already been deleted", id));
return false;
}
if ((object.canBeDeleted() == null) || force) {
if (object.canBeDeleted() != null) {
log.info("Force to delete object {} that can't be deleted", id);
}
_dbClient.internalRemoveObjects(object);
return true;
}
System.out.println(String.format("The object %s can't be deleted", id));
return false;
}
use of com.emc.storageos.db.common.DependencyChecker in project coprhd-controller by CoprHD.
the class GarbageCollectorTests method testDependencyChecker.
@Test
public void testDependencyChecker() throws Exception {
int num_projects = 10;
int num_fs = 110;
initGCExecutor();
DependencyChecker checker = new DependencyChecker(_dbClient, _scanner);
VirtualPool vpool = new VirtualPool();
vpool.setId(URIUtil.createId(VirtualPool.class));
vpool.setLabel("GOLD");
vpool.setType("file");
vpool.setProtocols(new StringSet());
_dbClient.createObject(vpool);
List<URI> activeProjects = new ArrayList<URI>();
for (int i = 0; i < num_projects; i++) {
Project p = new Project();
p.setId(URIUtil.createId(Project.class));
p.setLabel("dependency test project");
_dbClient.createObject(p);
activeProjects.add(p.getId());
}
Assert.assertNull(checker.checkDependencies(vpool.getId(), VirtualPool.class, true));
Map<URI, List<URI>> activeFileSystems = new HashMap<URI, List<URI>>();
for (int i = 0; i < num_fs; i++) {
String label = "fileshare dependency tests " + i;
FileShare fs = new FileShare();
fs.setId(URIUtil.createId(FileShare.class));
fs.setLabel(label);
fs.setCapacity(102400L);
fs.setVirtualPool(vpool.getId());
SMBShareMap shareMap = new SMBShareMap();
shareMap.put("test", new SMBFileShare("blah", "blah", "blah", "blah", 1));
fs.setSMBFileShares(shareMap);
URI proj = activeProjects.get(new Random().nextInt(activeProjects.size()));
fs.setProject(new NamedURI(proj, label));
_dbClient.createObject(fs);
if (!activeFileSystems.containsKey(proj)) {
activeFileSystems.put(proj, new ArrayList<URI>());
}
activeFileSystems.get(fs.getProject().getURI()).add(fs.getId());
}
Assert.assertNotNull(checker.checkDependencies(vpool.getId(), VirtualPool.class, true));
for (int i = 0; i < num_projects; i++) {
if (activeFileSystems.containsKey(activeProjects.get(i))) {
Assert.assertNotNull(checker.checkDependencies(activeProjects.get(i), Project.class, true));
} else {
Assert.assertNull(checker.checkDependencies(activeProjects.get(i), Project.class, true));
}
}
List<URI> inactiveRefProjects = new ArrayList<URI>();
List<URI> lastRefProjects = new ArrayList<URI>();
for (Map.Entry<URI, List<URI>> entry : activeFileSystems.entrySet()) {
if (entry.getValue().size() % 3 == 0) {
// inactive all refs
for (URI uri : entry.getValue()) {
FileShare fs = new FileShare();
fs.setId(uri);
fs.setInactive(true);
_dbClient.updateAndReindexObject(fs);
}
inactiveRefProjects.add(entry.getKey());
} else if (entry.getValue().size() % 3 == 2) {
// inactive all but last ref
for (int i = 0; i < entry.getValue().size() - 1; i++) {
FileShare fs = new FileShare();
fs.setId(entry.getValue().get(i));
fs.setInactive(true);
_dbClient.updateAndReindexObject(fs);
}
lastRefProjects.add(entry.getKey());
} else {
continue;
}
}
Assert.assertNotNull(checker.checkDependencies(vpool.getId(), VirtualPool.class, true));
for (int i = 0; i < num_projects; i++) {
URI p = activeProjects.get(i);
if (inactiveRefProjects.contains(p)) {
Assert.assertNull(checker.checkDependencies(p, Project.class, true));
} else {
Assert.assertNotNull(checker.checkDependencies(p, Project.class, true));
if (lastRefProjects.contains(p)) {
URI lastFs = activeFileSystems.get(p).get(activeFileSystems.get(p).size() - 1);
FileShare fs = new FileShare();
fs.setId(lastFs);
fs.setInactive(true);
_dbClient.updateAndReindexObject(fs);
} else {
for (URI uri : activeFileSystems.get(p)) {
FileShare fs = new FileShare();
fs.setId(uri);
fs.setInactive(true);
_dbClient.updateAndReindexObject(fs);
}
}
}
}
Assert.assertNull(checker.checkDependencies(vpool.getId(), VirtualPool.class, true));
for (int i = 0; i < num_projects; i++) {
Assert.assertNull(checker.checkDependencies(activeProjects.get(i), Project.class, true));
Project p = new Project();
p.setId(activeProjects.get(i));
p.setInactive(true);
_dbClient.updateAndReindexObject(p);
}
_gcExecutor.runNow();
Assert.assertNull(checker.checkDependencies(vpool.getId(), VirtualPool.class, false));
vpool.setInactive(true);
_dbClient.updateAndReindexObject(vpool);
_gcExecutor.runNow();
Assert.assertNull(_dbClient.queryObject(VirtualPool.class, vpool.getId()));
}
Aggregations