use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method listSanpshotByPolicy.
@Override
public BiosCommandResult listSanpshotByPolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
FilePolicy sp = args.getFileProtectionPolicy();
FileShare fs = args.getFs();
String snapshotScheduleName = sp.getFilePolicyName() + "_" + args.getFsName();
if (sp.getPolicyStorageResources() != null && !sp.getPolicyStorageResources().isEmpty()) {
for (String uriResource : sp.getPolicyStorageResources()) {
PolicyStorageResource policyRes = _dbClient.queryObject(PolicyStorageResource.class, URI.create(uriResource));
if (policyRes != null && policyRes.getStorageSystem().equals(storageObj.getId())) {
snapshotScheduleName = policyRes.getPolicyNativeId();
break;
}
}
}
IsilonApi isi = getIsilonDevice(storageObj);
String resumeToken = null;
try {
do {
IsilonList<IsilonSnapshot> snapshots = isi.listSnapshotsCreatedByPolicy(resumeToken, snapshotScheduleName);
if (snapshots != null) {
for (IsilonSnapshot islon_snap : snapshots.getList()) {
_log.info("file policy snapshot is : " + islon_snap.getName());
Snapshot snap = new Snapshot();
snap.setLabel(islon_snap.getName());
snap.setMountPath(islon_snap.getPath());
snap.setName(islon_snap.getName());
snap.setId(URIUtil.createId(Snapshot.class));
snap.setOpStatus(new OpStatusMap());
snap.setProject(new NamedURI(fs.getProject().getURI(), islon_snap.getName()));
snap.setMountPath(getSnapshotPath(islon_snap.getPath(), islon_snap.getName()));
snap.setParent(new NamedURI(fs.getId(), islon_snap.getName()));
StringMap map = new StringMap();
Long createdTime = Long.parseLong(islon_snap.getCreated()) * SEC_IN_MILLI;
String expiresTime = "Never";
if (islon_snap.getExpires() != null && !islon_snap.getExpires().isEmpty()) {
Long expTime = Long.parseLong(islon_snap.getExpires()) * SEC_IN_MILLI;
expiresTime = expTime.toString();
}
map.put("created", createdTime.toString());
map.put("expires", expiresTime);
map.put("schedule", sp.getFilePolicyName());
snap.setExtensions(map);
_dbClient.updateObject(snap);
}
resumeToken = snapshots.getToken();
}
} while (resumeToken != null && !resumeToken.equalsIgnoreCase("null"));
} catch (IsilonException e) {
_log.error("listing snapshot by file policy failed.", e);
return BiosCommandResult.createErrorResult(e);
}
Task task = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), args.getOpId());
// set task to completed and progress to 100 and store in DB, so waiting thread in apisvc can read it.
task.ready();
task.setProgress(100);
_dbClient.updateObject(task);
return BiosCommandResult.createSuccessfulResult();
}
use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class DbCli method dumpBeanProperties.
/**
* Dump the contents in xml format
*
* @param pds
* @param object
* @throws Exception
*/
private <T extends DataObject> void dumpBeanProperties(PropertyDescriptor[] pds, T object) throws Exception {
Element record = doc.createElement("record");
record.setAttribute("id", object.getId().toString());
schemaNode.appendChild(record);
// Add readOnlyField node.
Element readOnlyElement = doc.createElement("readOnlyField");
record.appendChild(readOnlyElement);
System.out.println("id: " + object.getId().toString());
Object objValue;
Class type;
for (PropertyDescriptor pd : pds) {
objValue = pd.getReadMethod().invoke(object);
if (objValue == null) {
continue;
}
// Skip password property.
if (pd.getName().toLowerCase().matches("[a-zA-Z\\d]*password[a-zA-Z\\d]*")) {
continue;
}
// Skip some properties.
if (pd.getName().equals("class") || pd.getName().equals("id")) {
Element readOnlyfieldNode = doc.createElement("field");
// delete the prefix string "class "
readOnlyfieldNode.setAttribute("type", pd.getPropertyType().toString().substring(6));
readOnlyfieldNode.setAttribute("name", pd.getName().toString());
readOnlyfieldNode.setAttribute("value", objValue.toString());
readOnlyElement.appendChild(readOnlyfieldNode);
continue;
}
// Skip the fields without @Name annotation
Name name = pd.getReadMethod().getAnnotation(Name.class);
if (name == null) {
log.info("Ignore data object fields without @Name annotation, fieldName={}.", pd.getName());
continue;
}
// use value from @Name instead of mtehod name
String objKey = name.value();
type = pd.getPropertyType();
if (DEBUG) {
System.out.print("\t" + pd.getPropertyType() + "\t" + objKey + " = ");
}
Element fieldNode = doc.createElement("field");
// delete the prefix string "class "
fieldNode.setAttribute("type", type.toString().substring(6));
fieldNode.setAttribute("name", objKey);
if (type == StringSetMap.class) {
StringSetMap stringSetMap = (StringSetMap) objValue;
FieldType.marshall(stringSetMap, fieldNode, StringSetMapWrapper.class);
} else if (type == StringSet.class) {
StringSet stringSet = (StringSet) objValue;
FieldType.marshall(stringSet, fieldNode, StringSetWrapper.class);
} else if (type == ScopedLabelSet.class) {
ScopedLabelSet scopedLabelSet = (ScopedLabelSet) objValue;
FieldType.marshall(scopedLabelSet, fieldNode, ScopedLabelSetWrapper.class);
} else if (type == OpStatusMap.class) {
OpStatusMap opStatusMap = (OpStatusMap) objValue;
FieldType.marshall(opStatusMap, fieldNode, OpStatusMapWrapper.class);
} else if (type == StringMap.class) {
StringMap stringMap = (StringMap) objValue;
FieldType.marshall(stringMap, fieldNode, StringMapWrapper.class);
} else if (type == FSExportMap.class) {
FSExportMap fSExportMap = (FSExportMap) objValue;
FieldType.marshall(fSExportMap, fieldNode, FSExportMapWrapper.class);
} else if (type == SMBShareMap.class) {
SMBShareMap sMBShareMap = (SMBShareMap) objValue;
FieldType.marshall(sMBShareMap, fieldNode, SMBShareMapWrapper.class);
} else {
fieldNode.setAttribute("value", objValue.toString());
}
record.appendChild(fieldNode);
}
}
use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class DBClient method printBeanProperties.
/**
* @param clazz
* @param object
* @param criterias
* Filter with some verify simple criteria
* @return Whether this record is print out
* @throws Exception
*/
private <T extends DataObject> boolean printBeanProperties(Class<T> clazz, T object, Map<String, String> criterias) throws Exception {
Map<String, String> localCriterias = new HashMap<>(criterias);
StringBuilder record = new StringBuilder();
record.append("id: " + object.getId().toString() + "\n");
boolean isPrint = true;
BeanInfo bInfo;
try {
bInfo = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException ex) {
log.error("Unexpected exception getting bean info", ex);
throw new RuntimeException("Unexpected exception getting bean info", ex);
}
PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
Object objValue;
Class type;
Set<String> ignoreList = new HashSet<>();
for (PropertyDescriptor pd : pds) {
// skip class property
if (pd.getName().equals("class") || pd.getName().equals("id")) {
continue;
}
Name nameAnnotation = pd.getReadMethod().getAnnotation(Name.class);
String objKey;
if (nameAnnotation == null) {
objKey = pd.getName();
} else {
objKey = nameAnnotation.value();
}
objValue = pd.getReadMethod().invoke(object);
if (!localCriterias.isEmpty()) {
if (localCriterias.containsKey(objKey)) {
if (!localCriterias.get(objKey).equalsIgnoreCase(String.valueOf(objValue))) {
isPrint = false;
break;
} else {
localCriterias.remove(objKey);
}
}
}
if (objValue == null) {
ignoreList.add(objKey);
continue;
}
if (isEmptyStr(objValue)) {
ignoreList.add(objKey);
continue;
}
record.append("\t" + objKey + " = ");
Encrypt encryptAnnotation = pd.getReadMethod().getAnnotation(Encrypt.class);
if (encryptAnnotation != null) {
record.append("*** ENCRYPTED CONTENT ***\n");
continue;
}
type = pd.getPropertyType();
if (type == URI.class) {
record.append("URI: " + objValue + "\n");
} else if (type == StringMap.class) {
record.append("StringMap " + objValue + "\n");
} else if (type == StringSet.class) {
record.append("StringSet " + objValue + "\n");
} else if (type == OpStatusMap.class) {
record.append("OpStatusMap " + objValue + "\n");
} else {
record.append(objValue + "\n");
}
}
if (this.showModificationTime) {
Column<CompositeColumnName> latestField = _dbClient.getLatestModifiedField(TypeMap.getDoType(clazz), object.getId(), ignoreList);
if (latestField != null) {
record.append(String.format("The latest modified time is %s on Field(%s).\n", new Date(latestField.getTimestamp() / 1000), latestField.getName().getOne()));
}
}
if (isPrint) {
if (!localCriterias.isEmpty()) {
String errMsg = String.format("The filters %s are not available for the CF %s", localCriterias.keySet(), clazz);
throw new IllegalArgumentException(errMsg);
}
System.out.println(record.toString());
}
return isPrint;
}
use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class UnManagedFilesystemService method ingestFileQuotaDirectories.
private void ingestFileQuotaDirectories(FileShare parentFS) throws IOException {
String parentFsNativeGUID = parentFS.getNativeGuid();
URIQueryResultList result = new URIQueryResultList();
List<QuotaDirectory> quotaDirectories = new ArrayList<>();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getUnManagedFileQuotaDirectoryInfoParentNativeGUIdConstraint(parentFsNativeGUID), result);
List<UnManagedFileQuotaDirectory> unManagedFileQuotaDirectories = _dbClient.queryObject(UnManagedFileQuotaDirectory.class, result);
_logger.info("found {} quota directories for fs {}", unManagedFileQuotaDirectories.size(), parentFS.getId());
for (UnManagedFileQuotaDirectory unManagedFileQuotaDirectory : unManagedFileQuotaDirectories) {
QuotaDirectory quotaDirectory = new QuotaDirectory();
quotaDirectory.setId(URIUtil.createId(QuotaDirectory.class));
quotaDirectory.setParent(new NamedURI(parentFS.getId(), unManagedFileQuotaDirectory.getLabel()));
quotaDirectory.setNativeId(unManagedFileQuotaDirectory.getNativeId());
quotaDirectory.setLabel(unManagedFileQuotaDirectory.getLabel());
quotaDirectory.setOpStatus(new OpStatusMap());
quotaDirectory.setProject(new NamedURI(parentFS.getProject().getURI(), unManagedFileQuotaDirectory.getLabel()));
quotaDirectory.setTenant(new NamedURI(parentFS.getTenant().getURI(), unManagedFileQuotaDirectory.getLabel()));
quotaDirectory.setInactive(false);
quotaDirectory.setSoftLimit(unManagedFileQuotaDirectory.getSoftLimit() != null && unManagedFileQuotaDirectory.getSoftLimit() != 0 ? unManagedFileQuotaDirectory.getSoftLimit() : parentFS.getSoftLimit() != null ? parentFS.getSoftLimit().intValue() : 0);
quotaDirectory.setSoftGrace(unManagedFileQuotaDirectory.getSoftGrace() != null && unManagedFileQuotaDirectory.getSoftGrace() != 0 ? unManagedFileQuotaDirectory.getSoftGrace() : parentFS.getSoftGracePeriod() != null ? parentFS.getSoftGracePeriod() : 0);
quotaDirectory.setNotificationLimit(unManagedFileQuotaDirectory.getNotificationLimit() != null && unManagedFileQuotaDirectory.getNotificationLimit() != 0 ? unManagedFileQuotaDirectory.getNotificationLimit() : parentFS.getNotificationLimit() != null ? parentFS.getNotificationLimit().intValue() : 0);
String convertedName = unManagedFileQuotaDirectory.getLabel().replaceAll("[^\\dA-Za-z_]", "");
_logger.info("FileService::QuotaDirectory Original name {} and converted name {}", unManagedFileQuotaDirectory.getLabel(), convertedName);
quotaDirectory.setName(convertedName);
if (unManagedFileQuotaDirectory.getOpLock() != null) {
quotaDirectory.setOpLock(unManagedFileQuotaDirectory.getOpLock());
} else {
quotaDirectory.setOpLock(true);
}
quotaDirectory.setSize(unManagedFileQuotaDirectory.getSize());
quotaDirectory.setSecurityStyle(unManagedFileQuotaDirectory.getSecurityStyle());
quotaDirectory.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirectory, parentFS.getName()));
// check for file extensions
if (null != unManagedFileQuotaDirectory.getExtensions() && !unManagedFileQuotaDirectory.getExtensions().isEmpty()) {
StringMap extensions = new StringMap();
if (null != unManagedFileQuotaDirectory.getExtensions().get(QUOTA)) {
extensions.put(QUOTA, unManagedFileQuotaDirectory.getExtensions().get(QUOTA));
quotaDirectory.setExtensions(extensions);
}
}
quotaDirectories.add(quotaDirectory);
}
if (!quotaDirectories.isEmpty()) {
_dbClient.updateObject(quotaDirectories);
}
if (!unManagedFileQuotaDirectories.isEmpty()) {
unManagedFileQuotaDirectories.forEach(unManagedFileQuotaDir -> unManagedFileQuotaDir.setInactive(true));
_dbClient.updateObject(unManagedFileQuotaDirectories);
_logger.info("ingested {} quota directories for fs {}", unManagedFileQuotaDirectories.size(), parentFS.getId());
}
}
use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class VPlexBlockServiceApiImpl method prepareMigration.
/**
* Prepares a migration for the passed virtual volume specifying the source
* and target volumes for the migration.
*
* @param virtualVolumeURI The URI of the virtual volume.
* @param sourceURI The URI of the source volume for the migration.
* @param targetURI The URI of the target volume for the migration.
* @param token The task identifier.
*
* @return A reference to a newly created Migration.
*/
public Migration prepareMigration(URI virtualVolumeURI, URI sourceURI, URI targetURI, String token) {
Migration migration = new Migration();
migration.setId(URIUtil.createId(Migration.class));
migration.setVolume(virtualVolumeURI);
migration.setSource(sourceURI);
migration.setTarget(targetURI);
_dbClient.createObject(migration);
migration.setOpStatus(new OpStatusMap());
Operation op = _dbClient.createTaskOpStatus(Migration.class, migration.getId(), token, ResourceOperationTypeEnum.MIGRATE_BLOCK_VOLUME);
migration.getOpStatus().put(token, op);
_dbClient.updateObject(migration);
return migration;
}
Aggregations