Commit 012172a1 authored by Spiros Koulouzis's avatar Spiros Koulouzis

implement max num of VMs

parent b9276067
......@@ -72,7 +72,7 @@
<h1 class="page-header">Files and Libraries</h1>
<h3 id="artifact_gwt_json_overlay">GWT JSON Overlay</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p> <p>
The <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> JSON Overlay library provides the JSON Overlays that
can be used to access the Web service API for this application.
......@@ -97,7 +97,7 @@
</tbody>
</table>
<h3 id="artifact_java_json_client_library">Java JSON Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The Java client-side library is used to provide the set of Java objects that can be serialized
to/from JSON using <a href="http://jackson.codehaus.org/">Jackson</a>. This is useful for accessing the
......@@ -116,18 +116,18 @@
<tbody data-link="row" class="rowlink">
<tr class="clickable-row" data-href="drip-api-json-client.jar">
<td><span class="downloadfile-name">drip-api-json-client.jar</span></td>
<td><span class="downloadfile-size">18.03K</span></td>
<td><span class="downloadfile-size">18.04K</span></td>
<td><span class="downloadfile-description">The binaries for the Java JSON client library.</span></td>
</tr>
<tr class="clickable-row" data-href="drip-api-json-client-json-sources.jar">
<td><span class="downloadfile-name">drip-api-json-client-json-sources.jar</span></td>
<td><span class="downloadfile-size">14.89K</span></td>
<td><span class="downloadfile-size">14.88K</span></td>
<td><span class="downloadfile-description">The sources for the Java JSON client library.</span></td>
</tr>
</tbody>
</table>
<h3 id="artifact_java_xml_client_library">Java XML Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The Java client-side library is used to access the Web service API for this application using Java.
</p>
......@@ -149,13 +149,13 @@
</tr>
<tr class="clickable-row" data-href="drip-api-xml-client-xml-sources.jar">
<td><span class="downloadfile-name">drip-api-xml-client-xml-sources.jar</span></td>
<td><span class="downloadfile-size">23.27K</span></td>
<td><span class="downloadfile-size">23.28K</span></td>
<td><span class="downloadfile-description">The sources for the Java XML client library.</span></td>
</tr>
</tbody>
</table>
<h3 id="artifact_js_client_library">JavaScript Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The JavaScript client-side library defines classes that can be (de)serialized to/from JSON.
This is useful for accessing the resources that are published by this application, but only
......@@ -190,7 +190,7 @@
</tbody>
</table>
<h3 id="artifact_php_json_client_library">PHP JSON Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The PHP JSON client-side library defines the PHP classes that can be (de)serialized to/from JSON.
This is useful for accessing the resources that are published by this application, but only
......@@ -213,13 +213,13 @@
<tbody data-link="row" class="rowlink">
<tr class="clickable-row" data-href="drip-api-php.zip">
<td><span class="downloadfile-name">drip-api-php.zip</span></td>
<td><span class="downloadfile-size">6.67K</span></td>
<td><span class="downloadfile-size">6.58K</span></td>
<td><span class="downloadfile-description">&nbsp;</span></td>
</tr>
</tbody>
</table>
<h3 id="artifact_php_xml_client_library">PHP XML Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The PHP client-side library defines the PHP classes that can be (de)serialized to/from XML.
This is useful for accessing the resources that are published by this application, but only
......@@ -251,7 +251,7 @@
</tbody>
</table>
<h3 id="artifact_ruby_json_client_library">Ruby JSON Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The Ruby JSON client-side library defines the Ruby classes that can be (de)serialized to/from JSON.
This is useful for accessing the REST endpoints that are published by this application, but only
......
This diff is collapsed.
......@@ -81,7 +81,7 @@ class</p>
</thead>
<tbody>
<tr>
<td> <span class="property-name">cloudDeploymentDomain</span>
<td> <span class="property-name">vmType</span>
</td>
<td> <span class="datatype-reference">string
</span>
......@@ -90,7 +90,7 @@ class</p>
</td>
</tr>
<tr>
<td> <span class="property-name">start</span>
<td> <span class="property-name">end</span>
</td>
<td> <span class="datatype-reference">number
</span>
......@@ -99,36 +99,36 @@ class</p>
</td>
</tr>
<tr>
<td> <span class="property-name">end</span>
<td> <span class="property-name">host</span>
</td>
<td> <span class="datatype-reference">number
<td> <span class="datatype-reference">string
</span>
</td>
<td> <span class="property-description"></span>
</td>
</tr>
<tr>
<td> <span class="property-name">vmType</span>
<td> <span class="property-name">delta</span>
</td>
<td> <span class="datatype-reference">string
<td> <span class="datatype-reference">number
</span>
</td>
<td> <span class="property-description"></span>
</td>
</tr>
<tr>
<td> <span class="property-name">host</span>
<td> <span class="property-name">start</span>
</td>
<td> <span class="datatype-reference">string
<td> <span class="datatype-reference">number
</span>
</td>
<td> <span class="property-description"></span>
</td>
</tr>
<tr>
<td> <span class="property-name">delta</span>
<td> <span class="property-name">cloudDeploymentDomain</span>
</td>
<td> <span class="datatype-reference">number
<td> <span class="datatype-reference">string
</span>
</td>
<td> <span class="property-description"></span>
......@@ -167,12 +167,12 @@ No need to set during a POST</span></td>
<p class="lead">Example</p>
<pre class="prettyprint language-js example">{
&quot;cloudDeploymentDomain&quot; : &quot;us-east-1&quot;,
&quot;start&quot; : 12345,
&quot;end&quot; : 12345,
&quot;vmType&quot; : &quot;...&quot;,
&quot;end&quot; : 12345,
&quot;host&quot; : &quot;147.228.242.58&quot;,
&quot;delta&quot; : 12345,
&quot;start&quot; : 12345,
&quot;cloudDeploymentDomain&quot; : &quot;us-east-1&quot;,
&quot;owner&quot; : &quot;user1&quot;,
&quot;id&quot; : &quot;58e3946e0fb4f562d84ba1ad&quot;,
&quot;timestamp&quot; : 1499793079011
......
......@@ -821,17 +821,17 @@ class]]>
<xs:complexContent>
<xs:extension base="ownedObject">
<xs:sequence>
<xs:element name="vmType" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="delta" type="xs:dateTime" minOccurs="0">
</xs:element>
<xs:element name="host" type="xs:string" minOccurs="0">
<xs:element name="vmType" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="start" type="xs:dateTime" minOccurs="0">
</xs:element>
<xs:element name="end" type="xs:dateTime" minOccurs="0">
</xs:element>
<xs:element name="cloudDeploymentDomain" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="end" type="xs:dateTime" minOccurs="0">
<xs:element name="host" type="xs:string" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:extension>
......
......@@ -144,12 +144,12 @@ Content-Type: application/json
<code class="prettyprint language-js">
[ {
&quot;cloudDeploymentDomain&quot; : &quot;us-east-1&quot;,
&quot;start&quot; : 12345,
&quot;end&quot; : 12345,
&quot;vmType&quot; : &quot;...&quot;,
&quot;end&quot; : 12345,
&quot;host&quot; : &quot;147.228.242.58&quot;,
&quot;delta&quot; : 12345,
&quot;start&quot; : 12345,
&quot;cloudDeploymentDomain&quot; : &quot;us-east-1&quot;,
&quot;owner&quot; : &quot;user1&quot;,
&quot;id&quot; : &quot;58e3946e0fb4f562d84ba1ad&quot;,
&quot;timestamp&quot; : 1499793079011
......@@ -514,12 +514,12 @@ Content-Type: application/json
<code class="prettyprint language-js">
{
&quot;cloudDeploymentDomain&quot; : &quot;us-east-1&quot;,
&quot;start&quot; : 12345,
&quot;end&quot; : 12345,
&quot;vmType&quot; : &quot;...&quot;,
&quot;end&quot; : 12345,
&quot;host&quot; : &quot;147.228.242.58&quot;,
&quot;delta&quot; : 12345,
&quot;start&quot; : 12345,
&quot;cloudDeploymentDomain&quot; : &quot;us-east-1&quot;,
&quot;owner&quot; : &quot;user1&quot;,
&quot;id&quot; : &quot;58e3946e0fb4f562d84ba1ad&quot;,
&quot;timestamp&quot; : 1499793079011
......
......@@ -554,6 +554,12 @@ Content-Type: application/json
<td><span class="parameter-description">&nbsp;</span></td>
<td><span class="parameter-constraints">required</span></td>
</tr>
<tr>
<td><span class="parameter-name">max_vm</span></td>
<td>query</td>
<td><span class="parameter-description">&nbsp;</span></td>
<td><span class="parameter-constraints">int</span></td>
</tr>
<tr>
<td><span class="parameter-name">preferred_provider</span></td>
<td>query</td>
......
......@@ -220,12 +220,12 @@ It is created automatically. No need to set during a POST</span></td>
<p class="lead">Example</p>
<pre class="prettyprint language-xml example">&lt;b-----&gt;
&lt;vmType&gt;...&lt;/vmType&gt;
&lt;delta&gt;...&lt;/delta&gt;
&lt;host&gt;147.228.242.58&lt;/host&gt;
&lt;vmType&gt;...&lt;/vmType&gt;
&lt;start&gt;...&lt;/start&gt;
&lt;cloudDeploymentDomain&gt;us-east-1&lt;/cloudDeploymentDomain&gt;
&lt;end&gt;...&lt;/end&gt;
&lt;cloudDeploymentDomain&gt;us-east-1&lt;/cloudDeploymentDomain&gt;
&lt;host&gt;147.228.242.58&lt;/host&gt;
&lt;owner&gt;user1&lt;/owner&gt;
&lt;/b-----&gt;
</pre>
......
......@@ -72,7 +72,7 @@
<h1 class="page-header">Files and Libraries</h1>
<h3 id="artifact_gwt_json_overlay">GWT JSON Overlay</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p> <p>
The <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> JSON Overlay library provides the JSON Overlays that
can be used to access the Web service API for this application.
......@@ -97,7 +97,7 @@
</tbody>
</table>
<h3 id="artifact_java_json_client_library">Java JSON Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The Java client-side library is used to provide the set of Java objects that can be serialized
to/from JSON using <a href="http://jackson.codehaus.org/">Jackson</a>. This is useful for accessing the
......@@ -116,18 +116,18 @@
<tbody data-link="row" class="rowlink">
<tr class="clickable-row" data-href="drip-api-json-client.jar">
<td><span class="downloadfile-name">drip-api-json-client.jar</span></td>
<td><span class="downloadfile-size">18.03K</span></td>
<td><span class="downloadfile-size">18.04K</span></td>
<td><span class="downloadfile-description">The binaries for the Java JSON client library.</span></td>
</tr>
<tr class="clickable-row" data-href="drip-api-json-client-json-sources.jar">
<td><span class="downloadfile-name">drip-api-json-client-json-sources.jar</span></td>
<td><span class="downloadfile-size">14.89K</span></td>
<td><span class="downloadfile-size">14.88K</span></td>
<td><span class="downloadfile-description">The sources for the Java JSON client library.</span></td>
</tr>
</tbody>
</table>
<h3 id="artifact_java_xml_client_library">Java XML Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The Java client-side library is used to access the Web service API for this application using Java.
</p>
......@@ -149,13 +149,13 @@
</tr>
<tr class="clickable-row" data-href="drip-api-xml-client-xml-sources.jar">
<td><span class="downloadfile-name">drip-api-xml-client-xml-sources.jar</span></td>
<td><span class="downloadfile-size">23.27K</span></td>
<td><span class="downloadfile-size">23.28K</span></td>
<td><span class="downloadfile-description">The sources for the Java XML client library.</span></td>
</tr>
</tbody>
</table>
<h3 id="artifact_js_client_library">JavaScript Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The JavaScript client-side library defines classes that can be (de)serialized to/from JSON.
This is useful for accessing the resources that are published by this application, but only
......@@ -190,7 +190,7 @@
</tbody>
</table>
<h3 id="artifact_php_json_client_library">PHP JSON Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The PHP JSON client-side library defines the PHP classes that can be (de)serialized to/from JSON.
This is useful for accessing the resources that are published by this application, but only
......@@ -213,13 +213,13 @@
<tbody data-link="row" class="rowlink">
<tr class="clickable-row" data-href="drip-api-php.zip">
<td><span class="downloadfile-name">drip-api-php.zip</span></td>
<td><span class="downloadfile-size">6.67K</span></td>
<td><span class="downloadfile-size">6.58K</span></td>
<td><span class="downloadfile-description">&nbsp;</span></td>
</tr>
</tbody>
</table>
<h3 id="artifact_php_xml_client_library">PHP XML Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The PHP client-side library defines the PHP classes that can be (de)serialized to/from XML.
This is useful for accessing the resources that are published by this application, but only
......@@ -251,7 +251,7 @@
</tbody>
</table>
<h3 id="artifact_ruby_json_client_library">Ruby JSON Client Library</h3>
<p class="lead">Created January 25, 2018</p>
<p class="lead">Created January 26, 2018</p>
<p><p>
The Ruby JSON client-side library defines the Ruby classes that can be (de)serialized to/from JSON.
This is useful for accessing the REST endpoints that are published by this application, but only
......
This diff is collapsed.
......@@ -81,7 +81,7 @@ class</p>
</thead>
<tbody>
<tr>
<td> <span class="property-name">delta</span>
<td> <span class="property-name">start</span>
</td>
<td> <span class="datatype-reference">number
</span>
......@@ -90,36 +90,36 @@ class</p>
</td>
</tr>
<tr>
<td> <span class="property-name">host</span>
<td> <span class="property-name">delta</span>
</td>
<td> <span class="datatype-reference">string
<td> <span class="datatype-reference">number
</span>
</td>
<td> <span class="property-description"></span>
</td>
</tr>
<tr>
<td> <span class="property-name">end</span>
<td> <span class="property-name">vmType</span>
</td>
<td> <span class="datatype-reference">number
<td> <span class="datatype-reference">string
</span>
</td>
<td> <span class="property-description"></span>
</td>
</tr>
<tr>
<td> <span class="property-name">vmType</span>
<td> <span class="property-name">end</span>
</td>
<td> <span class="datatype-reference">string
<td> <span class="datatype-reference">number
</span>
</td>
<td> <span class="property-description"></span>
</td>
</tr>
<tr>
<td> <span class="property-name">start</span>
<td> <span class="property-name">host</span>
</td>
<td> <span class="datatype-reference">number
<td> <span class="datatype-reference">string
</span>
</td>
<td> <span class="property-description"></span>
......@@ -167,11 +167,11 @@ No need to set during a POST</span></td>
<p class="lead">Example</p>
<pre class="prettyprint language-js example">{
&quot;start&quot; : 12345,
&quot;delta&quot; : 12345,
&quot;host&quot; : &quot;147.228.242.58&quot;,
&quot;end&quot; : 12345,
&quot;vmType&quot; : &quot;...&quot;,
&quot;start&quot; : 12345,
&quot;end&quot; : 12345,
&quot;host&quot; : &quot;147.228.242.58&quot;,
&quot;cloudDeploymentDomain&quot; : &quot;us-east-1&quot;,
&quot;owner&quot; : &quot;user1&quot;,
&quot;id&quot; : &quot;58e3946e0fb4f562d84ba1ad&quot;,
......
......@@ -69,7 +69,7 @@ class</p>
<dl class="dl-horizontal">
<dt>Subtypes</dt>
<dd><a href="json_KeyPair.html">KeyPair</a>, <a href="json_ScaleRequest.html">ScaleRequest</a>, <a href="json_AnsibleOutput.html">AnsibleOutput</a>, <a href="json_CloudCredentials.html">CloudCredentials</a>, <a href="json_BenchmarkResult.html">BenchmarkResult</a>, <a href="json_DeployResponse.html">DeployResponse</a>, <a href="json_DRIPLogRecord.html">DRIPLogRecord</a>, <a href="json_ProvisionRequest.html">ProvisionRequest</a>, <a href="json_Script.html">Script</a>, <a href="json_KeyValueHolder.html">KeyValueHolder</a>, <a href="json_DeployRequest.html">DeployRequest</a>, <a href="json_ProvisionResponse.html">ProvisionResponse</a>, <a href="json_MonitorringMessage.html">MonitorringMessage</a></dd>
<dd><a href="json_KeyPair.html">KeyPair</a>, <a href="json_AnsibleOutput.html">AnsibleOutput</a>, <a href="json_ScaleRequest.html">ScaleRequest</a>, <a href="json_CloudCredentials.html">CloudCredentials</a>, <a href="json_BenchmarkResult.html">BenchmarkResult</a>, <a href="json_DeployResponse.html">DeployResponse</a>, <a href="json_DRIPLogRecord.html">DRIPLogRecord</a>, <a href="json_ProvisionRequest.html">ProvisionRequest</a>, <a href="json_Script.html">Script</a>, <a href="json_KeyValueHolder.html">KeyValueHolder</a>, <a href="json_DeployRequest.html">DeployRequest</a>, <a href="json_MonitorringMessage.html">MonitorringMessage</a>, <a href="json_ProvisionResponse.html">ProvisionResponse</a></dd>
</dl>
<table class="table datatype-properties">
......
......@@ -821,17 +821,17 @@ class]]>
<xs:complexContent>
<xs:extension base="ownedObject">
<xs:sequence>
<xs:element name="host" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="delta" type="xs:dateTime" minOccurs="0">
</xs:element>
<xs:element name="cloudDeploymentDomain" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="vmType" type="xs:string" minOccurs="0">
<xs:element name="start" type="xs:dateTime" minOccurs="0">
</xs:element>
<xs:element name="end" type="xs:dateTime" minOccurs="0">
</xs:element>
<xs:element name="start" type="xs:dateTime" minOccurs="0">
<xs:element name="vmType" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="host" type="xs:string" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:extension>
......
......@@ -144,11 +144,11 @@ Content-Type: application/json
<code class="prettyprint language-js">
[ {
&quot;start&quot; : 12345,
&quot;delta&quot; : 12345,
&quot;host&quot; : &quot;147.228.242.58&quot;,
&quot;end&quot; : 12345,
&quot;vmType&quot; : &quot;...&quot;,
&quot;start&quot; : 12345,
&quot;end&quot; : 12345,
&quot;host&quot; : &quot;147.228.242.58&quot;,
&quot;cloudDeploymentDomain&quot; : &quot;us-east-1&quot;,
&quot;owner&quot; : &quot;user1&quot;,
&quot;id&quot; : &quot;58e3946e0fb4f562d84ba1ad&quot;,
......@@ -514,11 +514,11 @@ Content-Type: application/json
<code class="prettyprint language-js">
{
&quot;start&quot; : 12345,
&quot;delta&quot; : 12345,
&quot;host&quot; : &quot;147.228.242.58&quot;,
&quot;end&quot; : 12345,
&quot;vmType&quot; : &quot;...&quot;,
&quot;start&quot; : 12345,
&quot;end&quot; : 12345,
&quot;host&quot; : &quot;147.228.242.58&quot;,
&quot;cloudDeploymentDomain&quot; : &quot;us-east-1&quot;,
&quot;owner&quot; : &quot;user1&quot;,
&quot;id&quot; : &quot;58e3946e0fb4f562d84ba1ad&quot;,
......
......@@ -554,6 +554,12 @@ Content-Type: application/json
<td><span class="parameter-description">&nbsp;</span></td>
<td><span class="parameter-constraints">required</span></td>
</tr>
<tr>
<td><span class="parameter-name">max_vm</span></td>
<td>query</td>
<td><span class="parameter-description">&nbsp;</span></td>
<td><span class="parameter-constraints">int</span></td>
</tr>
<tr>
<td><span class="parameter-name">preferred_provider</span></td>
<td>query</td>
......
......@@ -220,12 +220,12 @@ It is created automatically. No need to set during a POST</span></td>
<p class="lead">Example</p>
<pre class="prettyprint language-xml example">&lt;b-----&gt;
&lt;host&gt;147.228.242.58&lt;/host&gt;
&lt;delta&gt;...&lt;/delta&gt;
&lt;cloudDeploymentDomain&gt;us-east-1&lt;/cloudDeploymentDomain&gt;
&lt;vmType&gt;...&lt;/vmType&gt;
&lt;end&gt;...&lt;/end&gt;
&lt;start&gt;...&lt;/start&gt;
&lt;end&gt;...&lt;/end&gt;
&lt;vmType&gt;...&lt;/vmType&gt;
&lt;host&gt;147.228.242.58&lt;/host&gt;
&lt;owner&gt;user1&lt;/owner&gt;
&lt;/b-----&gt;
</pre>
......
......@@ -79,9 +79,9 @@ public class PlannerService {
logger.addHandler(new DRIPLogHandler(messageBrokerHost));
}
public PlanResponse getPlan(String toscaId, String cloudProvider) throws JSONException, UnsupportedEncodingException, IOException, TimeoutException, InterruptedException {
public PlanResponse getPlan(String toscaId, String cloudProvider, int maxVM) throws JSONException, UnsupportedEncodingException, IOException, TimeoutException, InterruptedException {
try (DRIPCaller planner = new PlannerCaller(messageBrokerHost)) {
Message plannerInvokationMessage = buildPlannerMessage(toscaId);
Message plannerInvokationMessage = buildPlannerMessage(toscaId,maxVM);
logger.log(Level.INFO, "Calling planner");
plannerInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
Message plannerReturnedMessage = (planner.call(plannerInvokationMessage));
......@@ -105,7 +105,6 @@ public class PlannerService {
}
String domainName = getBestDomain(cloudProvider);
// SimplePlanContainer simplePlan = P2PConverter.convert(jsonArrayString.toString(), "vm_user", "Ubuntu 16.04", clusterType);
SimplePlanContainer simplePlan = P2PConverter.transfer(jsonArrayString.toString(), "vm_user", domainName, cloudProvider);
PlanResponse topLevel = new PlanResponse();
......@@ -132,14 +131,14 @@ public class PlannerService {
}
}
private Message buildPlannerMessage(String toscaId) throws JSONException, UnsupportedEncodingException {
ToscaRepresentation t2 = toscaService.findOne(toscaId);
if (t2 == null) {
private Message buildPlannerMessage(String toscaId, int maxVM) throws JSONException, UnsupportedEncodingException {
ToscaRepresentation toscaRepresentation = toscaService.findOne(toscaId);
if (toscaRepresentation == null) {
throw new BadRequestException();
}
logger.log(Level.INFO, "Building invokation message for planner");
Map<String, Object> map = t2.getKeyValue();
Map<String, Object> map = toscaRepresentation.getKeyValue();
String json = Converter.map2JsonString(map);
json = json.replaceAll("\\uff0E", ".");
byte[] bytes = json.getBytes();
......@@ -150,9 +149,16 @@ public class PlannerService {
String charset = "UTF-8";
jsonArgument.setValue(new String(bytes, charset));
jsonArgument.setEncoding(charset);
jsonArgument.setName("input");
jsonArgument.setName("tosca_input");
parameters.add(jsonArgument);
MessageParameter maxVMsArgument = new MessageParameter();
maxVMsArgument.setValue(String.valueOf(maxVM));
maxVMsArgument.setEncoding(charset);
maxVMsArgument.setName("max_vm");
parameters.add(maxVMsArgument);
invokationMessage.setParameters(parameters);
invokationMessage.setCreationDate((System.currentTimeMillis()));
return invokationMessage;
......
......@@ -65,7 +65,7 @@ public class PlannerController0 {
String yaml = plan0.file;
yaml = yaml.replaceAll("\\\\n", "\n");
String id = toscaService.saveYamlString(yaml, null);
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse plan1 = plannerService.getPlan(id, null);
nl.uva.sne.drip.drip.commons.data.v1.external.PlanResponse plan1 = plannerService.getPlan(id, null,-1);
Result r = new Result();
r.info = ("INFO");
r.status = ("Success");
......
......@@ -79,16 +79,18 @@ public class PlannerController {
*
* @param toscaId. The id of the TOSCA description
* @param preferredProvider
* @param maxVm
* @return the id of the created plan
*/
@RequestMapping(value = "/plan/{tosca_id}", method = RequestMethod.GET, params = {"preferred_provider"})
@RequestMapping(value = "/plan/{tosca_id}", method = RequestMethod.GET, params = {"preferred_provider", "max_vm"})
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String plan(@PathVariable("tosca_id") String toscaId,
@RequestParam(value = "preferred_provider", required = false) String preferredProvider) {
@RequestParam(value = "preferred_provider", required = false) String preferredProvider,
@RequestParam(value = "max_vm", required = false) int maxVm) {
try {
PlanResponse plan = plannerService.getPlan(toscaId, preferredProvider);
PlanResponse plan = plannerService.getPlan(toscaId, preferredProvider, maxVm);
if (plan == null) {
throw new NotFoundException("Could not make plan");
}
......
......@@ -270,4 +270,20 @@ public class Converter {
return msg;
}
public static Number castToNumber(Object value) {
if (value instanceof Number) {
return (Number) value;
}
if (value instanceof String) {
Pattern p = Pattern.compile("-?\\d+");
Matcher m = p.matcher((CharSequence) value);
while (m.find()) {
return Integer.valueOf(m.group());
}
}
return null;
}
}
......@@ -112,15 +112,10 @@ public class P2PConverter {
private static int analyzeRequirements(Map<String, String> map) {
int size = 5;
String memSizeGB = map.get("mem_size");
Pattern p = Pattern.compile("-?\\d+");
Matcher m = p.matcher(memSizeGB);
int memSize = 0;
while (m.find()) {
memSize = Integer.valueOf(m.group());
}
if (Integer.valueOf(map.get("num_cpus")) >= 16 && memSize >= 32) {
Number memSize = Converter.castToNumber(map.get("mem_size"));
Number num_cpus = Converter.castToNumber(map.get("num_cpus"));
if (num_cpus.intValue() >= 16 && memSize.intValue() >= 32) {
size = 10;
}
return size;
......
......@@ -2,6 +2,8 @@
from toscaparser import *
from toscaparser.tosca_template import ToscaTemplate
import toscaparser.utils.yamlparser
import re
import operator
class DumpPlanner:
......@@ -39,7 +41,10 @@ class DumpPlanner:
return self.yaml_dict_tpl['topology_template']['node_templates']
def get_network_templates(self):
if 'network_templates' in self.yaml_dict_tpl:
return self.yaml_dict_tpl['topology_template']['network_templates']
else:
return None
def get_artifacts(self, node):
if 'artifacts' in node:
......@@ -64,11 +69,42 @@ class DumpPlanner:
if 'properties' in node:
return node['properties']
def plan(self):
def cast_to_int(self,value):
if isinstance(value, int):
return value
if isinstance(value, str):
return int(re.findall("\d+", value)[0])
def sort_vms(self,vms,max_vms):
sorted_vms = []
vms_dict = {}
for vm in vms:
score = 0
score += self.cast_to_int(vm['host']['cpu_frequency'])
score += self.cast_to_int(vm['host']['mem_size'])
score += self.cast_to_int(vm['host']['num_cpus'])
score += self.cast_to_int(vm['host']['disk_size'])
vms_dict[vm['name']] = score
sorted_vms_dict = sorted(vms_dict.items(), key=operator.itemgetter(1),reverse=True)
counter = 0
for sorted_vm in sorted_vms_dict:
if counter >= max_vms:
break
for vm in vms:
if sorted_vm[0] == vm['name']:
counter+=1
sorted_vms.append(vm)
break
return sorted_vms
def plan(self,max_vms):
network_templates = self.get_network_templates()
vms = []
if network_templates and network_templates['network'] and network_templates['network']['multicast'] == True:
vm = {}
vm['name'] = 'id'
vm['type'] = self.COMPUTE_TYPE
host = {}
host['cpu_frequency'] = '2.6GHz'
......@@ -86,6 +122,7 @@ class DumpPlanner:
vms.append(vm)
return vms
node_templates = self.get_node_templates()
hosted_nodes = self.get_hosted_nodes(node_templates)
......@@ -120,4 +157,8 @@ class DumpPlanner:
else:
vm['scaling_mode'] = 'single'
vms.append(vm)
if max_vms > -1 and len(vms) > max_vms:
vms = self.sort_vms(vms,max_vms)
return vms
......@@ -60,9 +60,20 @@ def handle_delivery(message):
parsed_json_message = json.loads(message)
params = parsed_json_message["parameters"]
owner = parsed_json_message['owner']
param = params[0]
value = json.loads(param['value'])
tosca_file_name = param["name"]
tosca_value = {}
tosca_file_name = ''
max_vms = -1
for param in params:
value = param['value']
name = param["name"]
if name == 'tosca_input':
tosca_value = json.loads(value)
tosca_file_name = name
if name == 'max_vm':
max_vms = int(value)
current_milli_time = lambda: int(round(time.time() * 1000))
......@@ -78,7 +89,7 @@ def handle_delivery(message):
if not os.path.exists(tosca_file_path):
os.makedirs(tosca_file_path)
with open(tosca_file_path + "/" + tosca_file_name + ".yml", 'w') as outfile:
outfile.write(json.dumps(value))
outfile.write(json.dumps(tosca_value))
response = {}
current_milli_time = lambda: int(round(time.time() * 1000))
......@@ -86,7 +97,7 @@ def handle_delivery(message):
response["parameters"] = []
if queue_name == "planner_queue":
planner = DumpPlanner(tosca_file_path + "/" + tosca_file_name + ".yml");
vm_nodes = planner.plan()
vm_nodes = planner.plan(max_vms)
for vm in vm_nodes:
parameter = {}
parameter['value'] = str(json.dumps(vm))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment