Skip to content

Commit 3c0086c

Browse files
committed
backend custom actions changes
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent d2132cb commit 3c0086c

File tree

17 files changed

+698
-112
lines changed

17 files changed

+698
-112
lines changed

api/src/main/java/com/cloud/extension/ExtensionCustomAction.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,85 @@
1717

1818
package com.cloud.extension;
1919

20+
import java.util.List;
21+
2022
import org.apache.cloudstack.api.Identity;
2123
import org.apache.cloudstack.api.InternalIdentity;
24+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
25+
import org.apache.commons.lang3.StringUtils;
26+
27+
import com.google.gson.Gson;
28+
import com.google.gson.GsonBuilder;
29+
import com.google.gson.reflect.TypeToken;
2230

2331
public interface ExtensionCustomAction extends InternalIdentity, Identity {
2432
String getName();
2533

2634
String getDescription();
2735

36+
long getExtensionId();
37+
2838
String getRolesList();
39+
40+
boolean isEnabled();
41+
42+
class Parameter {
43+
public enum Type {
44+
STRING,
45+
INTEGER,
46+
DECIMAL,
47+
BOOLEAN,
48+
UUID,
49+
DATE;
50+
51+
public static Type fromString(String value) {
52+
if (StringUtils.isBlank(value)) {
53+
return STRING;
54+
}
55+
try {
56+
return Type.valueOf(value.trim().toUpperCase());
57+
} catch (IllegalArgumentException ex) {
58+
return STRING;
59+
}
60+
}
61+
}
62+
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
63+
64+
final String name;
65+
final Type type;
66+
final boolean required;
67+
68+
public Parameter (String name, Type type, boolean required) {
69+
this.name = name;
70+
this.type = type;
71+
this.required = required;
72+
}
73+
74+
public String getName() {
75+
return name;
76+
}
77+
78+
public Type getType() {
79+
return type;
80+
}
81+
82+
public boolean isRequired() {
83+
return required;
84+
}
85+
86+
@Override
87+
public String toString() {
88+
return String.format("Parameter %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this,
89+
"name", "type", "required"));
90+
}
91+
92+
public static String toJsonFromList(List<Parameter> parameters) {
93+
return gson.toJson(parameters);
94+
}
95+
96+
public static List<Parameter> toListFromJson(String json) {
97+
java.lang.reflect.Type listType = new TypeToken<List<Parameter>>() {}.getType();
98+
return gson.fromJson(json, listType);
99+
}
100+
}
29101
}

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public class ApiConstants {
209209
public static final String EXTERNAL_UUID = "externaluuid";
210210
public static final String EXTERNAL_PROVISIONER = "externalprovisioner";
211211
public static final String EXTERNAL_DETAILS = "externaldetails";
212-
public static final String CUSTOM_ACTION_PARAMETERS = "parameters";
212+
public static final String PARAMETERS = "parameters";
213213
public static final String EXTENSION = "extension";
214214
public static final String EXTENSIONS = "extensions";
215215
public static final String EXTENSION_ID = "extensionid";
@@ -648,6 +648,7 @@ public class ApiConstants {
648648
public static final String ZONE_TOKEN = "zonetoken";
649649
public static final String DHCP_PROVIDER = "dhcpprovider";
650650
public static final String RESULT = "success";
651+
public static final String RESULT1 = "result";
651652
public static final String RESUME = "resume";
652653
public static final String LUN_ID = "lunId";
653654
public static final String IQN = "iqn";
@@ -1074,6 +1075,7 @@ public class ApiConstants {
10741075
public static final String OVM3_CLUSTER = "ovm3cluster";
10751076
public static final String OVM3_VIP = "ovm3vip";
10761077
public static final String CLEAN_UP_DETAILS = "cleanupdetails";
1078+
public static final String CLEAN_UP_PARAMETERS = "cleanupparameters";
10771079
public static final String VIRTUAL_SIZE = "virtualsize";
10781080
public static final String NETSCALER_CONTROLCENTER_ID = "netscalercontrolcenterid";
10791081
public static final String NETSCALER_SERVICEPACKAGE_ID = "netscalerservicepackageid";
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
18+
package org.apache.cloudstack.api.response;
19+
20+
import org.apache.cloudstack.api.ApiConstants;
21+
import org.apache.cloudstack.api.BaseResponse;
22+
23+
import com.cloud.serializer.Param;
24+
import com.google.gson.annotations.SerializedName;
25+
26+
public class ExtensionCustomActionParameterResponse extends BaseResponse {
27+
28+
@SerializedName(ApiConstants.NAME)
29+
@Param(description = "Name of the parameter")
30+
private String name;
31+
32+
@SerializedName(ApiConstants.TYPE)
33+
@Param(description = "Type of the parameter")
34+
private String type;
35+
36+
@SerializedName(ApiConstants.REQUIRED)
37+
@Param(description = "Whether the parameter is required or not")
38+
private Boolean required;
39+
40+
public ExtensionCustomActionParameterResponse(String name, String type, boolean required) {
41+
this.name = name;
42+
this.type = type;
43+
this.required = required;
44+
}
45+
46+
public void setName(String name) {
47+
this.name = name;
48+
}
49+
50+
public void setType(String type) {
51+
this.type = type;
52+
}
53+
54+
public void setRequired(Boolean required) {
55+
this.required = required;
56+
}
57+
}

api/src/main/java/org/apache/cloudstack/api/response/ExtensionCustomActionResponse.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626

2727
import java.util.Date;
2828
import java.util.Map;
29+
import java.util.Set;
2930

3031
@EntityReference(value = ExtensionCustomAction.class)
3132
public class ExtensionCustomActionResponse extends BaseResponse {
3233

3334
@SerializedName(ApiConstants.ID)
34-
@Param(description = "UUID of the extension custom action")
35+
@Param(description = "ID of the extension custom action")
3536
private String id;
3637

3738
@SerializedName(ApiConstants.NAME)
@@ -42,16 +43,28 @@ public class ExtensionCustomActionResponse extends BaseResponse {
4243
@Param(description = "Description of the extension custom action")
4344
private String description;
4445

46+
@SerializedName(ApiConstants.EXTENSION_ID)
47+
@Param(description = "ID of the extension that this extension custom action belongs to")
48+
private String extensionId;
49+
50+
@SerializedName(ApiConstants.EXTENSION_NAME)
51+
@Param(description = "Name of the extension that this extension custom action belongs to")
52+
private String extensionName;
53+
4554
@SerializedName(ApiConstants.ROLES_LIST)
4655
@Param(description = "Comma separated list of roles associated with the extension custom action")
4756
private String rolesList;
4857

4958
@SerializedName(ApiConstants.DETAILS)
50-
@Param(description = "the details of the extension")
59+
@Param(description = "Details of the extension custom action")
5160
private Map<String, String> details;
5261

62+
@SerializedName(ApiConstants.PARAMETERS)
63+
@Param(description = "List of the parameters for the action", responseObject = ExtensionCustomActionParameterResponse.class)
64+
private Set<ExtensionCustomActionParameterResponse> parameters;
65+
5366
@SerializedName(ApiConstants.CREATED)
54-
@Param(description = "Creation timestamp of the extension")
67+
@Param(description = "Creation timestamp of the extension custom action")
5568
private Date created;
5669

5770
public ExtensionCustomActionResponse(String id, String name, String description, String rolesList) {
@@ -85,6 +98,14 @@ public void setDescription(String description) {
8598
this.description = description;
8699
}
87100

101+
public void setExtensionId(String extensionId) {
102+
this.extensionId = extensionId;
103+
}
104+
105+
public void setExtensionName(String extensionName) {
106+
this.extensionName = extensionName;
107+
}
108+
88109
public String getRolesList() {
89110
return rolesList;
90111
}
@@ -93,6 +114,10 @@ public void setRolesList(String rolesList) {
93114
this.rolesList = rolesList;
94115
}
95116

117+
public void setParameters(Set<ExtensionCustomActionParameterResponse> parameters) {
118+
this.parameters = parameters;
119+
}
120+
96121
public void setDetails(Map<String, String> details) {
97122
this.details = details;
98123
}

api/src/main/java/org/apache/cloudstack/extension/CustomActionResponse.java renamed to api/src/main/java/org/apache/cloudstack/extension/CustomActionResultResponse.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,37 @@
1717

1818
package org.apache.cloudstack.extension;
1919

20-
import com.cloud.serializer.Param;
21-
import com.google.gson.annotations.SerializedName;
20+
import java.util.Map;
21+
2222
import org.apache.cloudstack.api.ApiConstants;
2323
import org.apache.cloudstack.api.BaseResponse;
2424

25-
import java.util.Map;
25+
import com.cloud.serializer.Param;
26+
import com.google.gson.annotations.SerializedName;
27+
28+
public class CustomActionResultResponse extends BaseResponse {
2629

27-
public class CustomActionResponse extends BaseResponse {
30+
@SerializedName(ApiConstants.ID)
31+
@Param(description = "ID of the action")
32+
private String id;
2833

29-
@SerializedName(ApiConstants.ACTION)
30-
@Param(description = "name of the action")
31-
private String actionName;
34+
@SerializedName(ApiConstants.NAME)
35+
@Param(description = "Name of the action")
36+
private String name;
3237

3338
@SerializedName(ApiConstants.DETAILS)
34-
@Param(description = "details of the custom action run")
35-
private Map details;
39+
@Param(description = "Details of the action execution")
40+
private Map<String, String> details;
3641

37-
public void setDetails(Map details) {
38-
this.details = details;
42+
public void setId(String id) {
43+
this.id = id;
3944
}
4045

41-
public void setActionName(String name) {
42-
this.actionName = name;
46+
public void setName(String name) {
47+
this.name = name;
48+
}
49+
50+
public void setDetails(Map<String, String> details) {
51+
this.details = details;
4352
}
4453
}

core/src/main/java/com/cloud/agent/api/RunCustomActionAnswer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public RunCustomActionAnswer() {
3333
public RunCustomActionAnswer(RunCustomActionCommand cmd, boolean success, String details) {
3434
super(cmd, success, details);
3535
runDetails = new HashMap<>();
36+
runDetails.put("success", String.valueOf(success));
3637
runDetails.put("result", details);
3738
}
3839

engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ CREATE TABLE IF NOT EXISTS `cloud`.`extension_custom_action` (
136136
`name` varchar(255) NOT NULL,
137137
`description` varchar(255) NOT NULL,
138138
`extension_id` bigint(20) unsigned NOT NULL,
139+
`resource_type` varchar(255),
139140
`roles_list` varchar(255) DEFAULT NULL,
141+
`enabled` boolean DEFAULT true,
140142
`created` datetime NOT NULL,
141143
`removed` datetime DEFAULT NULL,
142144
PRIMARY KEY (`id`),

0 commit comments

Comments
 (0)