Skip to content

Commit 923969a

Browse files
committed
Add new async parameter to create infrastruture calls
1 parent 87e393b commit 923969a

File tree

4 files changed

+163
-5
lines changed

4 files changed

+163
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ For more information about the IM capabilities check: [IM Web](http://www.grycap
77

88
The javadoc for this project can be found here: [Javadoc](http://indigo-dc.github.io/im-java-api/apidocs/)
99

10-
1. INSTALLATION
10+
1 INSTALLATION
1111
===============
1212

1313
1.1 REQUISITES
@@ -55,7 +55,7 @@ If you want you can define a **log4j.properties** to log the REST service calls.
5555
To configure the logger you have to create a **log4j.properties** file and set the logger properties.
5656
The log4j.properties file of the tests can help you with the logger configuration.
5757

58-
2. USAGE
58+
2 USAGE
5959
===============
6060
The tests defined in the class **InfrastructureManagerTest** show how to use the im-java-api.
6161
Also check the following lines to see some examples of use:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public enum ImValues {
2929
CONTMSG("contmsg"),
3030
RADL("radl"),
3131
STATE("state"),
32-
RECONFIGURE("reconfigure");
32+
RECONFIGURE("reconfigure"),
33+
OUTPUTS("outputs");
3334

3435
private final String value;
3536

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

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public class InfrastructureManager {
5050
private static final String PATH_SEPARATOR = "/";
5151
// IM REST parameters
5252
private static final String REST_PARAMETER_NAME_CONTEXT = "context";
53+
private static final String REST_PARAMETER_NAME_ASYNC = "async";
5354
private static final String REST_PARAMETER_NAME_VMLIST = "vm_list";
54-
private static final String REST_PARAMETER_INFRASTRUCTURE_OUTPUTS = "outputs";
5555

5656
private final ImClient imClient;
5757

@@ -248,6 +248,7 @@ public void destroyInfrastructure(String infId) throws ImClientException {
248248
* just after the VM addition
249249
* @return : list of URIs of the new virtual machines
250250
*/
251+
@Deprecated
251252
public InfrastructureUris addResource(String infId, String radlFile,
252253
BodyContentType bodyContentType, boolean... context)
253254
throws ImClientException {
@@ -258,6 +259,133 @@ public InfrastructureUris addResource(String infId, String radlFile,
258259
restParameter);
259260
}
260261

262+
/**
263+
* Add the resources specified in the body contents to the infrastructure with
264+
* ID 'infId'. The RADL restrictions are the same as in
265+
* <a href="http://www.grycap.upv.es/im/doc/xmlrpc.html#addresource-xmlrpc">
266+
* RPC-XML AddResource</a><br>
267+
* If success, it is returned a list of URIs of the new virtual machines. <br>
268+
* The context parameter is optional and is a flag to specify if the
269+
* contextualization step will be launched just after the VM addition.<br>
270+
* If not specified the contextualization flag is set to True.
271+
*
272+
* @param infId
273+
* : infrastructure id
274+
* @param radlFile
275+
* : file with the virtual machine properties and configuration
276+
* @param bodyContentType
277+
* : set the body content type. Can be RADL, RADL_JSON or TOSCA.
278+
* @return : list of URIs of the new virtual machines
279+
*/
280+
public InfrastructureUris addResource(String infId, String radlFile,
281+
BodyContentType bodyContentType) throws ImClientException {
282+
return addResourcesWithParameters(infId, radlFile, bodyContentType);
283+
}
284+
285+
/**
286+
* Add the resources specified in the body contents to the infrastructure with
287+
* ID 'infId'. The RADL restrictions are the same as in
288+
* <a href="http://www.grycap.upv.es/im/doc/xmlrpc.html#addresource-xmlrpc">
289+
* RPC-XML AddResource</a><br>
290+
* If success, it is returned a list of URIs of the new virtual machines. <br>
291+
* The context parameter is optional and is a flag to specify if the
292+
* contextualization step will be launched just after the VM addition.<br>
293+
* If not specified the contextualization flag is set to True.
294+
*
295+
* @param infId
296+
* : infrastructure id
297+
* @param radlFile
298+
* : file with the virtual machine properties and configuration
299+
* @param bodyContentType
300+
* : set the body content type. Can be RADL, RADL_JSON or TOSCA.
301+
* @param context
302+
* : flag to specify if the contextualization step will be launched
303+
* 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.
307+
* @return : list of URIs of the new virtual machines
308+
*/
309+
public InfrastructureUris addResource(String infId, String radlFile,
310+
BodyContentType bodyContentType, boolean context, boolean async)
311+
throws ImClientException {
312+
313+
RestParameter ctxParameter =
314+
createCallParameters(REST_PARAMETER_NAME_CONTEXT, context);
315+
RestParameter asyncParameter =
316+
createCallParameters(REST_PARAMETER_NAME_ASYNC, async);
317+
318+
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);
345+
}
346+
347+
/**
348+
* Add the resources specified in the body contents to the infrastructure with
349+
* ID 'infId'. The RADL restrictions are the same as in
350+
* <a href="http://www.grycap.upv.es/im/doc/xmlrpc.html#addresource-xmlrpc">
351+
* RPC-XML AddResource</a><br>
352+
* If success, it is returned a list of URIs of the new virtual machines. <br>
353+
* This call activates the contextualization step just after the VM addition.
354+
* <br>
355+
*
356+
* @param infId
357+
* : infrastructure id
358+
* @param radlFile
359+
* : file with the virtual machine properties and configuration
360+
* @param bodyContentType
361+
* : set the body content type. Can be RADL, RADL_JSON or TOSCA.
362+
* @return : list of URIs of the new virtual machines
363+
*/
364+
public InfrastructureUris addResourceAndContextualize(String infId,
365+
String radlFile, BodyContentType bodyContentType)
366+
throws ImClientException {
367+
368+
RestParameter ctxParameter =
369+
createCallParameters(REST_PARAMETER_NAME_CONTEXT, true);
370+
return addResourcesWithParameters(infId, radlFile, bodyContentType,
371+
ctxParameter);
372+
}
373+
374+
private InfrastructureUris addResourcesWithParameters(String infId,
375+
String radlFile, BodyContentType bodyContentType,
376+
RestParameter... parameters) throws ImClientException {
377+
378+
return getImClient().post(PATH_INFRASTRUCTURES + PATH_SEPARATOR + infId,
379+
radlFile, bodyContentType.getValue(), InfrastructureUris.class,
380+
parameters);
381+
}
382+
383+
private static RestParameter createCallParameters(String paramName,
384+
Object value) {
385+
return new Parameter(paramName, value);
386+
}
387+
388+
@Deprecated
261389
private static RestParameter createCallParameters(boolean... context) {
262390
return (context != null && context.length > 0)
263391
? new Parameter(REST_PARAMETER_NAME_CONTEXT, context[0])
@@ -498,7 +626,7 @@ public void reconfigure(String infId, String radlFile,
498626
public InfOutputValues getInfrastructureOutputs(String infId)
499627
throws ImClientException {
500628
String path = PATH_INFRASTRUCTURES + PATH_SEPARATOR + infId + PATH_SEPARATOR
501-
+ REST_PARAMETER_INFRASTRUCTURE_OUTPUTS;
629+
+ ImValues.OUTPUTS;
502630
return getImClient().get(path, InfOutputValues.class);
503631
}
504632

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,35 @@ public void testAddResourceContextFalse() throws ImClientException {
259259
Assert.assertEquals(false, infUris.getUris().get(0).getUri().isEmpty());
260260
}
261261

262+
@Test
263+
public void testAddResourceContext() throws ImClientException {
264+
InfrastructureUris infUris =
265+
getIm().addResourceAndContextualize(getInfrastructureId(),
266+
readFile(TOSCA_EXTRA_NODE_FILE_PATH), BodyContentType.TOSCA);
267+
268+
Assert.assertEquals(1, infUris.getUris().size());
269+
Assert.assertEquals(false, infUris.getUris().get(0).getUri().isEmpty());
270+
}
271+
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+
281+
@Test
282+
public void testAddResourceWithAllParams() throws ImClientException {
283+
InfrastructureUris infUris = getIm().addResource(getInfrastructureId(),
284+
readFile(TOSCA_EXTRA_NODE_FILE_PATH), BodyContentType.TOSCA, true,
285+
true);
286+
287+
Assert.assertEquals(1, infUris.getUris().size());
288+
Assert.assertEquals(false, infUris.getUris().get(0).getUri().isEmpty());
289+
}
290+
262291
@Test
263292
public void testRemoveResourceNoContext() throws ImClientException {
264293
getIm().removeResource(getInfrastructureId(), VM_DEFAULT_ID);

0 commit comments

Comments
 (0)