1616// under the License.
1717package org .apache .cloudstack .tosca .orchestrator ;
1818
19+ import com .cloud .api .ApiDispatcher ;
1920import com .cloud .exception .InvalidParameterValueException ;
2021import com .cloud .utils .UuidUtils ;
22+ import com .cloud .utils .component .ComponentContext ;
23+ import org .apache .cloudstack .api .command .user .vmgroup .CreateVMGroupCmd ;
24+ import org .apache .cloudstack .context .CallContext ;
2125import org .apache .cloudstack .persistence .iactemplatesprofile .IacResourceTypeVO ;
2226import org .apache .cloudstack .tosca .model .ToscaNodeTemplate ;
2327import org .apache .cloudstack .tosca .model .ToscaNodeType ;
@@ -49,6 +53,9 @@ public class ToscaOrchestrator {
4953 @ Inject
5054 private ToscaParser toscaParser ;
5155
56+ @ Inject
57+ private ApiDispatcher apiDispatcher ;
58+
5259 private Map <String , ToscaNodeType > toscaProfile ;
5360
5461 private ExecutorService executorPool ;
@@ -133,6 +140,7 @@ private CompletableFuture<String> buildNodeProvisioningTask(ToscaNodeTemplate no
133140 }
134141
135142 private CompletableFuture <String > provisionNode (ToscaNodeTemplate nodeTemplate ) {
143+ CallContext callerContext = CallContext .current ();
136144 String currentLogContextId = ThreadContext .get ("logcontextid" );
137145 String newTaskLogContextId = UuidUtils .first (UUID .randomUUID ().toString ());
138146 logger .info ("Submitting new task with [logcontextid] equal to [{}] for handling the provisioning of the following node: [{}]." , newTaskLogContextId , nodeTemplate .getName ());
@@ -144,6 +152,7 @@ private CompletableFuture<String> provisionNode(ToscaNodeTemplate nodeTemplate)
144152 int randomInt = random .nextInt ((4000 - 500 ) + 1 ) + 500 ;
145153 logger .debug ("sleeping for randomInt: [{}] ms" , randomInt );
146154 try {
155+ dispatchProvisioningCommand (callerContext , randomInt );
147156 Thread .sleep (randomInt );
148157 } catch (InterruptedException e ) {
149158 throw new RuntimeException (e );
@@ -155,6 +164,26 @@ private CompletableFuture<String> provisionNode(ToscaNodeTemplate nodeTemplate)
155164 }, executorPool );
156165 }
157166
167+ private void dispatchProvisioningCommand (CallContext ctx , int randomInt ) {
168+ logger .debug ("Constructing provisioning command" );
169+ CallContext .register (ctx , null );
170+ CreateVMGroupCmd cmd = new CreateVMGroupCmd ();
171+ cmd = ComponentContext .inject (cmd );
172+ Map <String , String > params = Map .of (
173+ "domainid" , "1" ,
174+ "account" , "admin" ,
175+ "name" , "instance-group-" + randomInt
176+ );
177+ try {
178+ apiDispatcher .dispatch (cmd , params , false );
179+ logger .info (cmd .getResponseObject ());
180+ } catch (Exception e ) {
181+
182+ } finally {
183+ CallContext .unregister ();
184+ }
185+ }
186+
158187 public void configureExecutorPool (int poolSize ) {
159188 logger .info ("Configuring TOSCA's fixed executor thread pool with [{}] threads." , poolSize );
160189 executorPool = Executors .newFixedThreadPool (poolSize );
0 commit comments