Search in sources :

Example 1 with PropertyListDataObject

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

the class ManagedCapacityImpl method run.

public void run() {
    if (Thread.currentThread().isInterrupted()) {
        return;
    } else {
        try {
            List<ManagedResourceCapacity> capList = getManagedCapacity().getResourceCapacityList();
            for (ManagedResourceCapacity cap : capList) {
                CapacityPropertyListTypes type = mapCapacityType(cap.getType());
                PropertyListDataObject resource = map(cap, type.toString());
                List<URI> dataResourcesURI = dbClient.queryByConstraint(AlternateIdConstraint.Factory.getConstraint(PropertyListDataObject.class, "resourceType", type.toString()));
                if (!dataResourcesURI.isEmpty()) {
                    resource.setId(dataResourcesURI.get(0));
                    resource.setCreationTime(Calendar.getInstance());
                    dbClient.updateAndReindexObject(resource);
                } else {
                    resource.setId(URIUtil.createId(PropertyListDataObject.class));
                    dbClient.createObject(resource);
                }
            }
        } catch (InterruptedException ie) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) ManagedResourceCapacity(com.emc.storageos.model.vpool.ManagedResourcesCapacity.ManagedResourceCapacity) URI(java.net.URI)

Example 2 with PropertyListDataObject

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

the class PropertyListDataObjectMapper method map.

public static <T> PropertyListDataObject map(T from, String type) {
    if (from == null) {
        return null;
    }
    PropertyListDataObject to = new PropertyListDataObject();
    to.setResourceType(type);
    try {
        BeanInfo bInfo = Introspector.getBeanInfo(from.getClass());
        PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
        for (int i = 0; i < pds.length; i++) {
            PropertyDescriptor pd = pds[i];
            // skip class property
            String pdName = pd.getName();
            if (pd.getName().equals("class")) {
                continue;
            }
            if (pdName.equals("Id")) {
                if (URI.class.isAssignableFrom(pd.getPropertyType())) {
                    URI value = (URI) pd.getReadMethod().invoke(from);
                    to.setId(value);
                }
            }
            if (pdName.equals("creationTime")) {
                if (Calendar.class.isAssignableFrom(pd.getPropertyType())) {
                    Calendar value = (Calendar) pd.getReadMethod().invoke(from);
                    to.setCreationTime(value);
                }
            } else {
                Object value = pd.getReadMethod().invoke(from);
                to.getResourceData().put(pdName, value.toString());
            }
        }
        return to;
    } catch (Exception ex) {
        throw DatabaseException.fatals.deserializationFailed(from.getClass(), ex);
    }
}
Also used : PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) Calendar(java.util.Calendar) PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 3 with PropertyListDataObject

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

the class PropertyListDataObjectMapper method map.

public static <T> T map(PropertyListDataObject from, Class<T> clazz) {
    if (from == null) {
        return null;
    }
    T to;
    try {
        to = clazz.newInstance();
        BeanInfo bInfo = Introspector.getBeanInfo(clazz);
        PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
        for (int i = 0; i < pds.length; i++) {
            PropertyDescriptor pd = pds[i];
            // skip class property
            String pdName = pd.getName();
            if (pd.getName().equals("class")) {
                continue;
            }
            if (pdName.equals("id")) {
                if (URI.class.isAssignableFrom(pd.getPropertyType())) {
                    URI value = from.getId();
                    pd.getWriteMethod().invoke(to, value);
                }
            } else if (pdName.equals("creationTime")) {
                if (Calendar.class.isAssignableFrom(pd.getPropertyType())) {
                    Calendar value = from.getCreationTime();
                    pd.getWriteMethod().invoke(to, value);
                }
            } else {
                String strValue = from.getResourceData().get(pdName);
                Object value = valueFromString(strValue, pd);
                pd.getWriteMethod().invoke(to, value);
            }
        }
        return to;
    } catch (Exception ex) {
        throw DatabaseException.fatals.deserializationFailed(clazz, ex);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) Calendar(java.util.Calendar) PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 4 with PropertyListDataObject

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

the class CapacityService method getCapacityDataResource.

private ManagedResourcesCapacity getCapacityDataResource() throws Exception {
    ManagedResourcesCapacity capacities = new ManagedResourcesCapacity();
    for (CapacityResourceType capType : CapacityResourceType.values()) {
        ManagedCapacityImpl.CapacityPropertyListTypes resourceType = ManagedCapacityImpl.mapCapacityType(capType);
        List<URI> dataResourcesURI = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getConstraint(PropertyListDataObject.class, "resourceType", resourceType.toString()));
        if (dataResourcesURI.isEmpty()) {
            _log.warn("Failed to find capacity of type {} in the database, recompute", resourceType);
            throw new Exception("Failed to find capacity in the database");
        }
        PropertyListDataObject resource = _dbClient.queryObject(PropertyListDataObject.class, dataResourcesURI.get(0));
        ManagedResourceCapacity mCap = map(resource, ManagedResourceCapacity.class);
        capacities.getResourceCapacityList().add(mCap);
    }
    return capacities;
}
Also used : PropertyListDataObject(com.emc.storageos.db.client.model.PropertyListDataObject) CapacityResourceType(com.emc.storageos.model.vpool.ManagedResourcesCapacity.CapacityResourceType) ManagedResourceCapacity(com.emc.storageos.model.vpool.ManagedResourcesCapacity.ManagedResourceCapacity) ManagedResourcesCapacity(com.emc.storageos.model.vpool.ManagedResourcesCapacity) ManagedCapacityImpl(com.emc.storageos.volumecontroller.impl.ManagedCapacityImpl) URI(java.net.URI) IOException(java.io.IOException)

Aggregations

PropertyListDataObject (com.emc.storageos.db.client.model.PropertyListDataObject)4 URI (java.net.URI)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 ManagedResourceCapacity (com.emc.storageos.model.vpool.ManagedResourcesCapacity.ManagedResourceCapacity)2 BeanInfo (java.beans.BeanInfo)2 PropertyDescriptor (java.beans.PropertyDescriptor)2 Calendar (java.util.Calendar)2 ManagedResourcesCapacity (com.emc.storageos.model.vpool.ManagedResourcesCapacity)1 CapacityResourceType (com.emc.storageos.model.vpool.ManagedResourcesCapacity.CapacityResourceType)1 ManagedCapacityImpl (com.emc.storageos.volumecontroller.impl.ManagedCapacityImpl)1 IOException (java.io.IOException)1