use of com.peterphi.servicemanager.service.db.entity.ResourceInstanceEntity in project stdlib by petergeneric.
the class AzureInstanceActionDaemon method handle.
@Transactional
public void handle(final int id) {
ResourceInstanceEntity instance = dao.getById(id);
handle(instance);
dao.update(instance);
}
use of com.peterphi.servicemanager.service.db.entity.ResourceInstanceEntity in project stdlib by petergeneric.
the class ServiceManagerResourceRestServiceImpl method provision.
/**
* N.B. no {@link Transactional} annotation because the inner service does transaction management
*
* @param templateName
* @param parameters
*
* @return
*/
@Override
public ResourceInstanceDTO provision(final String templateName, final ProvisionResourceParametersDTO parameters) {
final Map<String, String> metadata = ResourceKVP.toMap(parameters.metadata);
ResourceInstanceEntity entity = service.newInstance(templateName, metadata);
return getInstanceById(entity.getId());
}
use of com.peterphi.servicemanager.service.db.entity.ResourceInstanceEntity in project stdlib by petergeneric.
the class ResourceProvisionService method newInstance.
@Transactional
public ResourceInstanceEntity newInstance(final ResourceTemplateEntity dbTemplate, final ResourceTemplateDefinition definition, Map<String, String> metadata) {
log.info("Provision new instance of template:" + dbTemplate.getId());
final AzureExistingVM azureVM = definition.azureExistingVM;
// TODO when adding a second provider make this generic so providers can be easily plugged in
List<ResourceInstanceEntity> running = getAllRunning(dbTemplate);
if (running.isEmpty()) {
log.info("Provision new instance of template: ");
ResourceInstanceEntity instance = new ResourceInstanceEntity();
instance.setTemplate(dbTemplate);
instance.setTemplateRevision(dbTemplate.getLatestRevision());
instance.setTemplateRevisionCounter(dbTemplate.getRevisions());
instance.setMetadata(metadata);
instance.setProvider(AzureExistingVMProvider.PROVIDER);
instance.setProviderInstanceId(azureVM.id);
// TODO in the future when making generic this should be TO_PROVISION and we should make the provision call asynchronously
instance.setState(ResourceInstanceState.PROVISIONING);
instance.setId(instanceDao.save(instance));
// Create a new instance
azureExistingVMProvider.start(azureVM, metadata);
return instance;
} else {
throw new IllegalArgumentException("Cannot create a new instance: provider is " + AzureExistingVMProvider.PROVIDER + " but an instance already appears to be running: " + running.stream().map(e -> e.getProviderInstanceId()).collect(Collectors.toList()));
}
}
use of com.peterphi.servicemanager.service.db.entity.ResourceInstanceEntity in project stdlib by petergeneric.
the class ServiceManagerResourceUIServiceImpl method doDiscard.
@Override
@Transactional
public Response doDiscard(final int id, final String nonce) {
nonceStore.validate(nonce);
final ResourceInstanceEntity instance = resourceProvisionService.discardInstance(id);
return Response.seeOther(URI.create("/resources/template/" + instance.getTemplate().getId())).build();
}
Aggregations