use of org.opentosca.container.core.next.model.ServiceTemplateInstance in project container by OpenTOSCA.
the class InstanceService method createServiceTemplateInstance.
private ServiceTemplateInstance createServiceTemplateInstance(final CsarId csarId, final String serviceTemplateName, final PlanInstance buildPlanInstance) throws InstantiationException, IllegalAccessException, IllegalArgumentException {
final Document propertiesAsDoc = createServiceInstanceInitialPropertiesFromServiceTemplate(csarId, serviceTemplateName);
final ServiceTemplateInstanceProperty property = convertDocumentToProperty(propertiesAsDoc, ServiceTemplateInstanceProperty.class);
final ServiceTemplateInstance instance = new ServiceTemplateInstance();
instance.setCsarId(csarId);
instance.setTemplateId(serviceTemplateName);
instance.setState(ServiceTemplateInstanceState.INITIAL);
instance.addProperty(property);
instance.addPlanInstance(buildPlanInstance);
instance.setCreationCorrelationId(buildPlanInstance.getCorrelationId());
this.serviceTemplateInstanceRepository.add(instance);
if (buildPlanInstance.getServiceTemplateInstance() == null) {
buildPlanInstance.setServiceTemplateInstance(instance);
}
new PlanInstanceRepository().update(buildPlanInstance);
return instance;
}
use of org.opentosca.container.core.next.model.ServiceTemplateInstance in project container by OpenTOSCA.
the class InstanceService method setServiceTemplateInstanceState.
public void setServiceTemplateInstanceState(final Long id, final String state) throws NotFoundException, IllegalArgumentException {
ServiceTemplateInstanceState newState;
try {
newState = ServiceTemplateInstanceState.valueOf(state);
} catch (final Exception e) {
final String msg = String.format("The given state %s is an illegal service template instance state.", state);
logger.error(msg, e);
throw new IllegalArgumentException(msg, e);
}
final ServiceTemplateInstance service = getServiceTemplateInstance(id, false);
service.setState(newState);
this.serviceTemplateInstanceRepository.update(service);
}
use of org.opentosca.container.core.next.model.ServiceTemplateInstance in project container by OpenTOSCA.
the class PlanService method getPlanInstances.
public List<PlanInstance> getPlanInstances(final Csar csar, final PlanType... planTypes) {
final ServiceTemplateInstanceRepository repo = new ServiceTemplateInstanceRepository();
final Collection<ServiceTemplateInstance> serviceInstances = repo.findByCsarId(csar.id());
return serviceInstances.stream().flatMap(sti -> sti.getPlanInstances().stream()).filter(p -> {
final PlanType currentType = PlanType.fromString(p.getType().toString());
return Arrays.stream(planTypes).anyMatch(pt -> pt.equals(currentType));
}).collect(Collectors.toList());
}
use of org.opentosca.container.core.next.model.ServiceTemplateInstance in project container by OpenTOSCA.
the class TestUtils method runBuildPlanExecution.
public static ServiceTemplateInstance runBuildPlanExecution(PlanService planService, InstanceService instanceService, Csar csar, TServiceTemplate serviceTemplate, TPlan buildPlan, List<org.opentosca.container.core.extension.TParameter> buildPlanInputParams) {
String buildPlanCorrelationId = planService.invokePlan(csar, serviceTemplate, -1L, buildPlan.getId(), buildPlanInputParams, PlanType.BUILD);
if (buildPlan.getPlanLanguage().contains("BPMN")) {
Collection<ServiceTemplateInstance> coll = instanceService.getServiceTemplateInstances(serviceTemplate.getId());
ServiceTemplateInstance s = new ServiceTemplateInstance();
while (coll.size() != 1) {
coll = instanceService.getServiceTemplateInstances(serviceTemplate.getId());
}
for (ServiceTemplateInstance serviceTemplateInstance : coll) {
s = serviceTemplateInstance;
}
ServiceTemplateInstanceState state = instanceService.getServiceTemplateInstanceState(s.getId());
while ((state != ServiceTemplateInstanceState.CREATED)) {
state = instanceService.getServiceTemplateInstanceState(s.getId());
}
return s;
}
PlanInstance buildPlanInstance = planService.getPlanInstanceByCorrelationId(buildPlanCorrelationId);
while (buildPlanInstance == null) {
buildPlanInstance = planService.getPlanInstanceByCorrelationId(buildPlanCorrelationId);
}
PlanInstanceState buildPlanInstanceState = buildPlanInstance.getState();
while (!buildPlanInstanceState.equals(PlanInstanceState.FINISHED)) {
buildPlanInstance = planService.getPlanInstance(buildPlanInstance.getId());
buildPlanInstanceState = buildPlanInstance.getState();
}
return instanceService.getServiceTemplateInstance(buildPlanInstance.getServiceTemplateInstance().getId(), false);
}
use of org.opentosca.container.core.next.model.ServiceTemplateInstance in project container by OpenTOSCA.
the class ServiceTemplateInstanceService method getServiceTemplateInstance.
public ServiceTemplateInstance getServiceTemplateInstance(final Long id, final boolean evaluatePropertyMappings) {
logger.debug("Requesting service template instance <{}>...", id);
final Optional<ServiceTemplateInstance> instance = this.serviceTemplateInstanceRepository.findWithNodeAndRelationshipTemplateInstancesById(id);
if (instance.isPresent()) {
final ServiceTemplateInstance result = instance.get();
if (evaluatePropertyMappings) {
helper.evaluatePropertyMappings(result);
}
return result;
}
logger.debug("Service Template Instance <" + id + "> not found.");
throw new NotFoundException("Service Template Instance <" + id + "> not found.");
}
Aggregations