use of org.ligoj.app.plugin.prov.model.ImportCatalogStatus in project plugin-prov by ligoj.
the class ImportCatalogResource method updateCatalog.
/**
* Update the catalog prices of related provider. Asynchronous operation.
*
* @param node
* The node (provider) to update.
* @return The catalog status.
*/
@POST
@Path("catalog/{node:service:prov:.+}")
public ImportCatalogStatus updateCatalog(@PathParam("node") final String node) {
final Node entity = nodeResource.checkWritableNode(node).getTool();
final ImportCatalogService catalogService = locator.getResource(entity.getId(), ImportCatalogService.class);
final ImportCatalogStatus task = startTask(entity.getId(), t -> {
t.setLocation(null);
t.setNbInstancePrices(null);
t.setNbInstanceTypes(null);
t.setNbStorageTypes(null);
t.setWorkload(0);
t.setDone(0);
t.setPhase(null);
});
final String user = securityHelper.getLogin();
// The import execution will done into another thread
Executors.newSingleThreadExecutor().submit(() -> {
Thread.sleep(50);
securityHelper.setUserName(user);
updateCatalog(catalogService, entity.getId());
return null;
});
return task;
}
use of org.ligoj.app.plugin.prov.model.ImportCatalogStatus in project plugin-prov by ligoj.
the class ImportCatalogResourceTest method assertFailed.
private void assertFailed(final ImportCatalogService service) throws Exception {
final ImportCatalogStatus status = repository.findBy("locked.id", "service:prov:test");
Assertions.assertEquals(DEFAULT_USER, status.getAuthor());
Assertions.assertNotNull(status.getEnd());
Assertions.assertNull(status.getLocation());
Assertions.assertEquals("service:prov:test", status.getLocked().getId());
Assertions.assertNotNull(status.getStart());
Assertions.assertNull(status.getLocation());
Assertions.assertEquals(0, status.getDone());
Assertions.assertEquals(0, status.getWorkload());
Assertions.assertTrue(status.isFinished());
Assertions.assertTrue(status.isFailed());
Assertions.assertEquals(0, status.getLastSuccess().getTime());
Assertions.assertEquals(-1, status.getNbInstancePrices().intValue());
Assertions.assertEquals(-1, status.getNbInstanceTypes().intValue());
Assertions.assertEquals(-1, status.getNbLocations().intValue());
Assertions.assertEquals(-1, status.getNbStorageTypes().intValue());
Mockito.verify(service).updateCatalog("service:prov:test");
}
use of org.ligoj.app.plugin.prov.model.ImportCatalogStatus in project plugin-prov by ligoj.
the class ImportCatalogResourceTest method updateCatalogFailed.
@Test
public void updateCatalogFailed() throws Exception {
final ImportCatalogResource resource = new ImportCatalogResource() {
@Override
public ImportCatalogStatus nextStep(final String node, final Consumer<ImportCatalogStatus> stepper) {
return super.nextStep(node, stepper);
}
};
applicationContext.getAutowireCapableBeanFactory().autowireBean(resource);
// Replace the locator for the custom provider
resource.locator = Mockito.mock(ServicePluginLocator.class);
final ImportCatalogService service = Mockito.mock(ImportCatalogService.class);
Mockito.when(resource.locator.getResource("service:prov:test", ImportCatalogService.class)).thenReturn(service);
Mockito.doThrow(new IOException()).when(service).updateCatalog("service:prov:test");
final ImportCatalogStatus status = resource.updateCatalog("service:prov:test:account");
Assertions.assertEquals(DEFAULT_USER, status.getAuthor());
Assertions.assertNull(status.getEnd());
Assertions.assertNull(status.getLocation());
Assertions.assertEquals("service:prov:test", status.getLocked().getId());
Assertions.assertNotNull(status.getStart());
Assertions.assertEquals(0, status.getDone());
Assertions.assertEquals(0, status.getWorkload());
}
use of org.ligoj.app.plugin.prov.model.ImportCatalogStatus in project plugin-prov by ligoj.
the class ImportCatalogResourceTest method newStatus.
private ImportCatalogStatus newStatus() {
ImportCatalogStatus status = new ImportCatalogStatus();
status.setLastSuccess(new Date(0));
status.setAuthor(DEFAULT_USER);
status.setNbInstancePrices(-1);
status.setNbInstanceTypes(-1);
status.setNbLocations(-1);
status.setNbStorageTypes(-1);
status.setStart(new Date());
status.setLocked(nodeRepository.findOne("service:prov:test"));
repository.saveAndFlush(status);
return status;
}
use of org.ligoj.app.plugin.prov.model.ImportCatalogStatus in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResourceTest method checkImportStatus.
private void checkImportStatus() {
final ImportCatalogStatus status = this.resource.getImportCatalogResource().getTask("service:prov:azure");
Assertions.assertEquals(14, status.getDone());
Assertions.assertEquals(14, status.getWorkload());
Assertions.assertEquals("finalize", status.getPhase());
Assertions.assertEquals(DEFAULT_USER, status.getAuthor());
Assertions.assertTrue(status.getNbInstancePrices().intValue() >= 46);
Assertions.assertEquals(5, status.getNbInstanceTypes().intValue());
Assertions.assertEquals(2, status.getNbLocations().intValue());
Assertions.assertEquals(5, status.getNbStorageTypes().intValue());
}
Aggregations