use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class DbClientImpl method setStatus.
@Override
@Deprecated
public void setStatus(Class<? extends DataObject> clazz, URI id, String opId, String status, String message) {
tracer.newTracer("write");
try {
DataObject doobj = clazz.newInstance();
doobj.setId(id);
doobj.setOpStatus(new OpStatusMap());
Operation op = new Operation();
op.setStatus(status);
if (message != null) {
op.setMessage(message);
}
doobj.getOpStatus().put(opId, op);
persistObject(doobj);
} catch (InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class DbClientImpl method printPersistedObject.
/**
* Print a stack trace to show the originator of the persist request.
* Used to detect anti-patterns. Calling this method is only for logging purposes.
*
* @param obj
* object to print stack
*/
private <T> void printPersistedObject(T obj) {
final String[] filterClasses = { "Workflow", "WorkflowStep", "WorkflowStepData", "Task" };
ArrayList<String> filterList = new ArrayList<>(Arrays.asList(filterClasses));
if (obj instanceof DataObject && !filterList.contains(obj.getClass().getSimpleName())) {
DataObject dobj = (DataObject) obj;
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
StringBuffer sb = new StringBuffer("Persisting obj: " + dobj.getId() + "\n");
sb.append("InActive: " + ((DataObject) obj).getInactive() + "\n");
sb.append("====================================================================================================\n");
for (int i = 0; i < elements.length; i++) {
if (elements[i].getClassName().contains("storageos")) {
sb.append("\t\t" + elements[i] + "\n");
}
}
sb.append("====================================================================================================");
_log.info(sb.toString());
}
}
use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class DbClientImpl method serializeTasks.
private void serializeTasks(DataObject dataObject, RowMutator mutator, List<URI> objectsToCleanup) {
OpStatusMap statusMap = dataObject.getOpStatus();
if (statusMap == null || statusMap.getChangedKeySet() == null || statusMap.getChangedKeySet().isEmpty()) {
return;
}
Set<String> addedSet = statusMap.getChangedKeySet();
if (addedSet != null) {
DataObjectType taskDoType = TypeMap.getDoType(Task.class);
Iterator<String> it = statusMap.getChangedKeySet().iterator();
while (it.hasNext()) {
String requestId = it.next();
Operation operation = statusMap.get(requestId);
Task task = TaskUtils.findTaskForRequestId(this, dataObject.getId(), requestId);
if (task == null) {
// Task doesn't currently exist for this id, so create it
task = new Task();
task.setId(URIUtil.createId(Task.class));
task.setRequestId(requestId);
task.setInactive(false);
task.setServiceCode(operation.getServiceCode());
task.setLabel(operation.getName());
task.setStatus(operation.getStatus());
task.setDescription(operation.getDescription());
Integer progress = operation.getProgress();
task.setProgress(progress != null ? progress : 0);
task.setMessage(operation.getMessage());
task.setAssociatedResources(operation.rawAssociatedResources());
task.setCreationTime(Calendar.getInstance());
task.setInactive(false);
task.setStartTime(operation.getStartTime());
task.setEndTime(getEndTime(operation));
// Often dummy objects are used that just contain an ID, for some things we need access to the entire object
DataObject loadedObject = dataObject;
if (StringUtils.isBlank(dataObject.getLabel())) {
loadedObject = this.queryObject(URIUtil.getModelClass(dataObject.getId()), dataObject.getId());
}
if (loadedObject == null) {
throw new RuntimeException("Task created on a resource which doesn't exist " + dataObject.getId());
}
task.setResource(new NamedURI(loadedObject.getId(), loadedObject.getLabel()));
URI tenantId = getTenantURI(loadedObject);
if (tenantId == null) {
task.setTenant(TenantOrg.SYSTEM_TENANT);
} else {
task.setTenant(tenantId);
}
_log.info("Created task {}, {}", task.getId() + " (" + task.getRequestId() + ")", task.getLabel());
} else {
// Task exists so update it
task.setServiceCode(operation.getServiceCode());
task.setStatus(operation.getStatus());
task.setMessage(operation.getMessage());
// Some code isn't updating progress to 100 when completed, so fix this here
if (Objects.equal(task.getStatus(), "pending") || Objects.equal(task.getStatus(), "suspended_no_error") || Objects.equal(task.getStatus(), "suspended_error")) {
task.setProgress(operation.getProgress());
} else {
task.setProgress(COMPLETED_PROGRESS);
}
task.setStartTime(operation.getStartTime());
task.setEndTime(getEndTime(operation));
task.setAssociatedResources(operation.rawAssociatedResources());
if (!Objects.equal(task.getStatus(), "pending")) {
_log.info("Completed task {}, {}", task.getId() + " (" + task.getRequestId() + ")", task.getStatus());
}
}
if (taskDoType.serialize(mutator, task)) {
objectsToCleanup.add(task.getId());
}
operation.addTask(dataObject.getId(), task);
}
}
}
use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class DbClientImpl method removeObject.
public void removeObject(Class<? extends DataObject> clazz, DataObject... object) {
tracer.newTracer("write");
List<DataObject> allObjects = Arrays.asList(object);
Keyspace ks = getKeyspace(clazz);
DataObjectType doType = null;
RemovedColumnsList removedList = new RemovedColumnsList();
for (DataObject dataObject : allObjects) {
_log.debug("Try to remove data object {}", dataObject.getId());
checkGeoVersionForMutation(dataObject);
doType = TypeMap.getDoType(dataObject.getClass());
// delete all the index columns for this object first
if (doType == null) {
throw new IllegalArgumentException();
}
Row<String, CompositeColumnName> row = queryRowWithAllColumns(ks, dataObject.getId(), doType.getCF());
if (row != null) {
Iterator<Column<CompositeColumnName>> it = row.getColumns().iterator();
String key = row.getKey();
while (it.hasNext()) {
Column<CompositeColumnName> column = it.next();
removedList.add(key, column);
}
}
}
if (!removedList.isEmpty()) {
boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
RowMutator mutator = new RowMutator(ks, retryFailedWriteWithLocalQuorum);
_indexCleaner.removeColumnAndIndex(mutator, doType, removedList);
}
}
use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class DbClientImpl method internalRemoveObjects.
public void internalRemoveObjects(DataObject... object) {
Map<Class<? extends DataObject>, List<DataObject>> typeObjMap = new HashMap<Class<? extends DataObject>, List<DataObject>>();
for (DataObject obj : object) {
List<DataObject> objTypeList = typeObjMap.get(obj.getClass());
if (objTypeList == null) {
objTypeList = new ArrayList<>();
typeObjMap.put(obj.getClass(), objTypeList);
}
objTypeList.add(obj);
}
for (Entry<Class<? extends DataObject>, List<DataObject>> entry : typeObjMap.entrySet()) {
List<DataObject> dbObjList = entry.getValue();
removeObject(entry.getKey(), dbObjList.toArray(new DataObject[dbObjList.size()]));
}
}
Aggregations