Search in sources :

Example 61 with DataObject

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);
    }
}
Also used : PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Operation(com.emc.storageos.db.client.model.Operation)

Example 62 with DataObject

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());
    }
}
Also used : PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) Constraint(com.emc.storageos.db.client.constraint.Constraint) DecommissionedConstraint(com.emc.storageos.db.client.constraint.DecommissionedConstraint)

Example 63 with DataObject

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);
        }
    }
}
Also used : Task(com.emc.storageos.db.client.model.Task) PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) NamedURI(com.emc.storageos.db.client.model.NamedURI) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 64 with DataObject

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);
    }
}
Also used : PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) Column(com.netflix.astyanax.model.Column) Keyspace(com.netflix.astyanax.Keyspace)

Example 65 with DataObject

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()]));
    }
}
Also used : PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) ColumnList(com.netflix.astyanax.model.ColumnList) QueryResultList(com.emc.storageos.db.client.constraint.QueryResultList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

DataObject (com.emc.storageos.db.client.model.DataObject)154 URI (java.net.URI)62 ArrayList (java.util.ArrayList)53 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)44 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)30 Volume (com.emc.storageos.db.client.model.Volume)26 NamedURI (com.emc.storageos.db.client.model.NamedURI)24 StringSet (com.emc.storageos.db.client.model.StringSet)23 HashMap (java.util.HashMap)22 BlockObject (com.emc.storageos.db.client.model.BlockObject)17 HashSet (java.util.HashSet)17 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)16 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)14 Operation (com.emc.storageos.db.client.model.Operation)13 List (java.util.List)10 Set (java.util.Set)10 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)9 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)8