use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class ScheduledEventService method createScheduledEvent.
/**
* Internal main function to create scheduled event.
* @param tenantId owner tenant Id
* @param param scheduled event creation param
* @param catalogService target catalog service
* @return ScheduledEvent
* @throws Exception
*/
private ScheduledEvent createScheduledEvent(StorageOSUser user, URI tenantId, ScheduledEventCreateParam param, CatalogService catalogService) throws Exception {
// INFINITE execution window
URI executionWindow = null;
if (catalogService.getExecutionWindowRequired()) {
if (catalogService.getDefaultExecutionWindowId() == null || catalogService.getDefaultExecutionWindowId().equals(ExecutionWindow.NEXT)) {
List<URI> executionWindows = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExecutionWindowTenantIdIdConstraint(tenantId.toString()));
Calendar currTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
executionWindow = getNextExecutionWindow(executionWindows, currTime);
} else {
executionWindow = catalogService.getDefaultExecutionWindowId().getURI();
}
ExecutionWindow window = client.findById(executionWindow);
String msg = match(param.getScheduleInfo(), window);
if (!msg.isEmpty()) {
throw APIException.badRequests.scheduleInfoNotMatchWithExecutionWindow(msg);
}
}
URI scheduledEventId = URIUtil.createId(ScheduledEvent.class);
param.getOrderCreateParam().setScheduledEventId(scheduledEventId);
Calendar scheduledTime = ScheduleTimeHelper.getFirstScheduledTime(param.getScheduleInfo());
param.getOrderCreateParam().setScheduledTime(ScheduleTimeHelper.convertCalendarToStr(scheduledTime));
param.getOrderCreateParam().setExecutionWindow(executionWindow);
OrderRestRep restRep = orderService.createOrder(param.getOrderCreateParam());
ScheduledEvent newObject = new ScheduledEvent();
newObject.setId(scheduledEventId);
newObject.setTenant(tenantId.toString());
newObject.setCatalogServiceId(param.getOrderCreateParam().getCatalogService());
newObject.setEventType(param.getScheduleInfo().getReoccurrence() == 1 ? ScheduledEventType.ONCE : ScheduledEventType.REOCCURRENCE);
if (catalogService.getApprovalRequired()) {
log.info(String.format("ScheduledEventr %s requires approval", newObject.getId()));
newObject.setEventStatus(ScheduledEventStatus.APPROVAL);
} else {
newObject.setEventStatus(ScheduledEventStatus.APPROVED);
}
newObject.setScheduleInfo(new String(org.apache.commons.codec.binary.Base64.encodeBase64(param.getScheduleInfo().serialize()), UTF_8));
if (executionWindow != null) {
newObject.setExecutionWindowId(new NamedURI(executionWindow, "ExecutionWindow"));
}
newObject.setLatestOrderId(restRep.getId());
newObject.setOrderCreationParam(new String(org.apache.commons.codec.binary.Base64.encodeBase64(param.getOrderCreateParam().serialize()), UTF_8));
newObject.setStorageOSUser(new String(org.apache.commons.codec.binary.Base64.encodeBase64(user.serialize()), UTF_8));
client.save(newObject);
log.info("Created a new scheduledEvent {}:{}", newObject.getId(), param.getScheduleInfo().toString());
return newObject;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class OrderMapper method createNewObject.
public static Order createNewObject(URI tenantId, OrderCreateParam param) {
Order newObject = new Order();
newObject.setId(URIUtil.createId(Order.class));
newObject.setTenant(tenantId.toString());
newObject.setCatalogServiceId(param.getCatalogService());
newObject.setWorkflowDocument(param.getWorkflowDocument());
if (param.getScheduledEventId() != null) {
newObject.setScheduledEventId(param.getScheduledEventId());
if (param.getScheduledTime() != null) {
newObject.setScheduledTime(ScheduleTimeHelper.convertStrToCalendar(param.getScheduledTime()));
}
if (param.getExecutionWindow() == null) {
newObject.setExecutionWindowId(null);
} else {
newObject.setExecutionWindowId(new NamedURI(param.getExecutionWindow(), "ExecutionWindow"));
}
}
updateObject(newObject, param);
return newObject;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class WorkflowHelper method addResource.
private static void addResource(Builder builder, NamedURI id, CustomServicesResourceDAOs resourceDAOs) {
final CustomServicesResourceDAO<?> dao = resourceDAOs.getByModel(URIUtil.getTypeName(id.getURI()));
if (null == dao) {
throw new RuntimeException("Resource type for " + id + " not found");
}
final CustomServicesPrimitiveResourceType resource = dao.getResource(id.getURI());
if (null == resource) {
throw new RuntimeException("Resource " + id + " not found");
}
builder.addResource(new ResourcePackage(CustomServicesPrimitiveMapper.map(resource), resource.resource()));
for (final NamedElement related : dao.listRelatedResources(id.getURI())) {
addResource(builder, new NamedURI(related.getId(), related.getName()), resourceDAOs);
}
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class CatalogBuilder method createCategory.
public CatalogCategory createCategory(String tenant, CategoryDef def, NamedURI parentId) {
String label = getMessage(getLabel(def));
String title = getMessage(def.title);
String description = getMessage(def.description);
CatalogCategory category = new CatalogCategory();
category.setTenant(tenant);
category.setLabel(StringUtils.deleteWhitespace(label));
category.setTitle(title);
category.setDescription(description);
category.setImage(def.image);
category.setCatalogCategoryId(parentId);
category.setSortedIndex(sortedIndexCounter++);
category.setVersion(def.version);
models.save(category);
NamedURI myId = new NamedURI(category.getId(), category.getLabel());
if (def.categories != null) {
for (CategoryDef categoryDef : def.categories) {
createCategory(tenant, categoryDef, myId);
}
}
if (def.services != null) {
for (ServiceDef serviceDef : def.services) {
createService(serviceDef, myId);
}
}
return category;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class CatalogServiceManagerImpl method createCatalogService.
public CatalogService createCatalogService(ServiceDef serviceDef, CatalogCategory parentCategory) {
CatalogBuilder builder = new CatalogBuilder(client, serviceDescriptors);
NamedURI namedUri = new NamedURI(parentCategory.getId(), parentCategory.getLabel());
CatalogService newService = builder.createService(serviceDef, namedUri);
newService.setSortedIndex(null);
client.save(newService);
return newService;
}
Aggregations