weizhouapache commented on code in PR #13032:
URL: https://github.com/apache/cloudstack/pull/13032#discussion_r3334172390
##########
framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManagerImpl.java:
##########
@@ -1499,6 +1998,177 @@ public CustomActionResultResponse
runCustomAction(RunCustomActionCmd cmd) {
return response;
}
+ /**
+ * Executes a custom action for a Network resource by delegating to an
+ * available {@link NetworkCustomActionProvider} (e.g.
NetworkExtensionElement).
+ * This path does NOT go through the agent framework.
+ */
+ protected CustomActionResultResponse runNetworkCustomAction(Network
network,
+ ExtensionCustomActionVO customActionVO, ExtensionVO extensionVO,
+ ExtensionCustomAction.ResourceType actionResourceType,
+ Map<String, String> cmdParameters) {
+
+ final String actionName = customActionVO.getName();
+ CustomActionResultResponse response = new CustomActionResultResponse();
+ response.setId(customActionVO.getUuid());
+ response.setName(actionName);
+ response.setObjectName("customactionresult");
+ Map<String, String> result = new HashMap<>();
+ response.setSuccess(false);
+ result.put(ApiConstants.MESSAGE, getActionMessage(false,
customActionVO, extensionVO, actionResourceType, network));
+
+ // Resolve action parameters
+ List<ExtensionCustomAction.Parameter> actionParameters = null;
+ Pair<Map<String, String>, Map<String, String>> allDetails =
+
extensionCustomActionDetailsDao.listDetailsKeyPairsWithVisibility(customActionVO.getId());
+ if (allDetails.second().containsKey(ApiConstants.PARAMETERS)) {
+ actionParameters = ExtensionCustomAction.Parameter.toListFromJson(
+ allDetails.second().get(ApiConstants.PARAMETERS));
+ }
+ Map<String, Object> parameters = null;
+ if (CollectionUtils.isNotEmpty(actionParameters)) {
+ parameters =
ExtensionCustomAction.Parameter.validateParameterValues(actionParameters,
cmdParameters);
+ }
+
+ // Find the provider name for this network (try CustomAction first,
then other services)
+ String providerName = null;
+ for (Service service : new Service[]{Service.CustomAction,
Service.SourceNat, Service.StaticNat,
+ Service.PortForwarding, Service.Firewall, Service.Gateway}) {
+ providerName =
networkServiceMapDao.getProviderForServiceInNetwork(network.getId(), service);
+ if (StringUtils.isNotBlank(providerName)) {
+ break;
+ }
+ }
+ if (StringUtils.isBlank(providerName)) {
+ logger.error("No network service provider found for network {}",
network.getId());
+ result.put(ApiConstants.DETAILS, "No network service provider
found for this network");
+ response.setResult(result);
+ return response;
+ }
+
+ // Get the network element implementing that provider
+ NetworkElement element =
networkModel.getElementImplementingProvider(providerName);
+ if (element == null) {
+ logger.error("No NetworkElement found implementing provider '{}'
for network {}", providerName, network.getId());
+ result.put(ApiConstants.DETAILS, "No network element found for
provider: " + providerName);
+ response.setResult(result);
+ return response;
+ }
Review Comment:
will fix it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]