Skip to content

Commit 203224f

Browse files
authored
Merge pull request #50 from indigo-dc/create-async-inf
Update code to asynchronously create infrastructures
2 parents f39337a + d6cb904 commit 203224f

File tree

3 files changed

+36
-42
lines changed

3 files changed

+36
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.project
44
.settings/*
55
/apidocs/
6+
/bin

src/main/java/es/upv/i3m/grycap/im/InfrastructureManager.java

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,27 @@ public InfrastructureUri createInfrastructure(String infrastructureDefinition,
116116
return getImClient().post(PATH_INFRASTRUCTURES, infrastructureDefinition,
117117
bodyContentType.getValue(), InfrastructureUri.class);
118118
}
119+
120+
/**
121+
* Create and configure an infrastructure with the requirements specified in
122+
* the document of the body contents.<br>
123+
* If success, it is returned the URI of the new infrastructure.
124+
* This call will not wait for the VMs to be created to return.
125+
*
126+
* @param infrastructureDefinition
127+
* : file with the virtual machine properties and configuration
128+
* @param bodyContentType
129+
* : set the body content type. Can be RADL, RADL_JSON or TOSCA.
130+
* @return : URI of the new infrastructure
131+
*/
132+
public InfrastructureUri createInfrastructureAsync(String infrastructureDefinition,
133+
BodyContentType bodyContentType) throws ImClientException {
134+
135+
RestParameter asyncParameter = createCallParameters(REST_PARAMETER_NAME_ASYNC, true);
136+
137+
return getImClient().post(PATH_INFRASTRUCTURES, infrastructureDefinition,
138+
bodyContentType.getValue(), InfrastructureUri.class, asyncParameter);
139+
}
119140

120141
/**
121142
* Return a list of URIs referencing the infrastructures associated to the IM
@@ -301,47 +322,18 @@ public InfrastructureUris addResource(String infId, String radlFile,
301322
* @param context
302323
* : flag to specify if the contextualization step will be launched
303324
* just after the VM addition
304-
* @param async
305-
* : flag to specify if the call has to wait for the VMs to be
306-
* created.
307325
* @return : list of URIs of the new virtual machines
308326
*/
309327
public InfrastructureUris addResource(String infId, String radlFile,
310-
BodyContentType bodyContentType, boolean context, boolean async)
328+
BodyContentType bodyContentType, boolean context)
311329
throws ImClientException {
312330

313331
RestParameter ctxParameter =
314332
createCallParameters(REST_PARAMETER_NAME_CONTEXT, context);
315-
RestParameter asyncParameter =
316-
createCallParameters(REST_PARAMETER_NAME_ASYNC, async);
317-
333+
318334
return getImClient().post(PATH_INFRASTRUCTURES + PATH_SEPARATOR + infId,
319-
radlFile, bodyContentType.getValue(), InfrastructureUris.class,
320-
ctxParameter, asyncParameter);
321-
}
322-
323-
/**
324-
* Add the resources specified in the body contents to the infrastructure with
325-
* ID 'infId'. The RADL restrictions are the same as in
326-
* <a href="http://www.grycap.upv.es/im/doc/xmlrpc.html#addresource-xmlrpc">
327-
* RPC-XML AddResource</a><br>
328-
* If success, it is returned a list of URIs of the new virtual machines. <br>
329-
* This call will not wait the VMs to be created.
330-
*
331-
* @param infId
332-
* : infrastructure id
333-
* @param radlFile
334-
* : file with the virtual machine properties and configuration
335-
* @param bodyContentType
336-
* : set the body content type. Can be RADL, RADL_JSON or TOSCA.
337-
* @return : list of URIs of the new virtual machines
338-
*/
339-
public InfrastructureUris addAsyncResource(String infId, String radlFile,
340-
BodyContentType bodyContentType) throws ImClientException {
341-
RestParameter asyncParameter =
342-
createCallParameters(REST_PARAMETER_NAME_ASYNC, true);
343-
return addResourcesWithParameters(infId, radlFile, bodyContentType,
344-
asyncParameter);
335+
radlFile, bodyContentType.getValue(), InfrastructureUris.class,
336+
ctxParameter);
345337
}
346338

347339
/**

src/test/java/es/upv/i3m/grycap/im/InfrastructureManagerTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ public void destroyInfrastructure() throws ImClientException {
133133
public void testCreateAndDestroyInfrastructure() {
134134
// Create empty test to check the @Before and @After methods
135135
}
136+
137+
@Test
138+
public void testCreateAndDestroyAsyncInfrastructure() throws ImClientException {
139+
InfrastructureUri newInfrastructureUri = getIm().createInfrastructureAsync(
140+
readFile(TOSCA_FILE_PATH), BodyContentType.TOSCA);
141+
String uri = newInfrastructureUri.getUri();
142+
Assert.assertEquals(false, uri.isEmpty());
143+
String infId = newInfrastructureUri.getInfrastructureId();
144+
getIm().destroyInfrastructure(infId);
145+
}
136146

137147
@Test
138148
public void testInfrastructuresList() throws ImClientException {
@@ -269,15 +279,6 @@ public void testAddResourceContext() throws ImClientException {
269279
Assert.assertEquals(false, infUris.getUris().get(0).getUri().isEmpty());
270280
}
271281

272-
@Test
273-
public void testAddResourceAsync() throws ImClientException {
274-
InfrastructureUris infUris = getIm().addAsyncResource(getInfrastructureId(),
275-
readFile(TOSCA_EXTRA_NODE_FILE_PATH), BodyContentType.TOSCA);
276-
277-
Assert.assertEquals(1, infUris.getUris().size());
278-
Assert.assertEquals(false, infUris.getUris().get(0).getUri().isEmpty());
279-
}
280-
281282
@Test
282283
public void testAddResourceWithAllParams() throws ImClientException {
283284
InfrastructureUris infUris = getIm().addResource(getInfrastructureId(),

0 commit comments

Comments
 (0)