Skip to content

Commit 803728b

Browse files
trying to trigger APIs
1 parent dd07fde commit 803728b

4 files changed

Lines changed: 74 additions & 9 deletions

File tree

plugins/iac/nimble/src/main/java/org/apache/cloudstack/tosca/orchestrator/ToscaOrchestrator.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
// under the License.
1717
package org.apache.cloudstack.tosca.orchestrator;
1818

19+
import com.cloud.api.ApiDispatcher;
1920
import com.cloud.exception.InvalidParameterValueException;
2021
import 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;
2125
import org.apache.cloudstack.persistence.iactemplatesprofile.IacResourceTypeVO;
2226
import org.apache.cloudstack.tosca.model.ToscaNodeTemplate;
2327
import 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);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.tosca.orchestrator.cmdbuilders;
18+
19+
import com.cloud.utils.component.ComponentContext;
20+
import org.apache.cloudstack.api.BaseCmd;
21+
import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
22+
import org.apache.cloudstack.tosca.model.ToscaNodeTemplate;
23+
24+
public class InstanceGroupCommandBuilder implements NodeCommandBuilder {
25+
@Override
26+
public BaseCmd buildProvisioningCommand(ToscaNodeTemplate toscaNodeTemplate) {
27+
CreateVMGroupCmd cmd = new CreateVMGroupCmd();
28+
cmd = ComponentContext.inject(cmd);
29+
return null;
30+
}
31+
32+
@Override
33+
public BaseCmd buildRollbackCommand(ToscaNodeTemplate toscaNodeTemplate) {
34+
return null;
35+
}
36+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.apache.cloudstack.tosca.orchestrator.cmdbuilders;
2+
3+
import org.apache.cloudstack.api.BaseCmd;
4+
import org.apache.cloudstack.tosca.model.ToscaNodeTemplate;
5+
6+
public interface NodeCommandBuilder {
7+
BaseCmd buildProvisioningCommand(ToscaNodeTemplate toscaNodeTemplate);
8+
BaseCmd buildRollbackCommand(ToscaNodeTemplate toscaNodeTemplate);
9+
}

plugins/iac/nimble/src/main/java/org/apache/cloudstack/tosca/orchestrator/commandbuilders/NodeCommandBuilder.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)