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();
}
}
}
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);
}
}
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);
}
}
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;
}
Aggregations