Skip to content

Commit b8ff2da

Browse files
committed
changes
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 086f57e commit b8ff2da

File tree

27 files changed

+559
-273
lines changed

27 files changed

+559
-273
lines changed

api/src/main/java/org/apache/cloudstack/acl/RoleType.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
import org.apache.logging.log4j.Logger;
2424
import org.apache.logging.log4j.LogManager;
2525

26+
import java.util.Collection;
27+
import java.util.EnumSet;
2628
import java.util.HashMap;
2729
import java.util.Map;
30+
import java.util.Set;
2831

2932
// Enum for default roles in CloudStack
3033
public enum RoleType {
@@ -100,6 +103,30 @@ public static Long getRoleByAccountType(final Long roleId, final Account.Type ac
100103
return roleId;
101104
}
102105

106+
public static int toCombinedMask(Collection<RoleType> roles) {
107+
int combinedMask = 0;
108+
if (roles != null) {
109+
for (RoleType role : roles) {
110+
combinedMask |= role.getMask();
111+
}
112+
}
113+
return combinedMask;
114+
}
115+
116+
public static Set<RoleType> fromCombinedMask(int combinedMask) {
117+
Set<RoleType> roles = EnumSet.noneOf(RoleType.class);
118+
for (RoleType roleType : RoleType.values()) {
119+
if ((combinedMask & roleType.getMask()) != 0) {
120+
roles.add(roleType);
121+
}
122+
}
123+
if (roles.isEmpty()) {
124+
roles.add(Unknown);
125+
}
126+
return roles;
127+
}
128+
129+
103130
/**
104131
* This method returns the role account type if the role isn't null, else it returns the default account type.
105132
* */

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ public class ApiConstants {
196196
public static final String END_IP = "endip";
197197
public static final String END_IPV6 = "endipv6";
198198
public static final String END_PORT = "endport";
199+
public static final String ENTRY_POINT = "entrypoint";
199200
public static final String ENTRY_TIME = "entrytime";
201+
public static final String ERROR_MESSAGE = "errormessage";
200202
public static final String EVENT_ID = "eventid";
201203
public static final String EVENT_TYPE = "eventtype";
202204
public static final String EXPIRES = "expires";
@@ -207,18 +209,10 @@ public class ApiConstants {
207209
public static final String EXTRA_DHCP_OPTION_VALUE = "extradhcpvalue";
208210
public static final String EXTERNAL = "external";
209211
public static final String EXTERNAL_UUID = "externaluuid";
210-
public static final String EXTERNAL_PROVISIONER = "externalprovisioner";
211212
public static final String EXTERNAL_DETAILS = "externaldetails";
212213
public static final String PARAMETERS = "parameters";
213-
public static final String EXTENSION = "extension";
214-
public static final String EXTENSIONS = "extensions";
215214
public static final String EXTENSION_ID = "extensionid";
216215
public static final String EXTENSION_NAME = "extensionname";
217-
public static final String EXTENSION_RESOURCE_ID = "extensionresourceid";
218-
public static final String EXTENSION_RESOURCE_MAP = "extensionresourcemap";
219-
220-
public static final String EXTENSION_CUSTOM_ACTION_ID = "customactionid";
221-
public static final String SCRIPT = "script";
222216
public static final String FENCE = "fence";
223217
public static final String FETCH_LATEST = "fetchlatest";
224218
public static final String FILESYSTEM = "filesystem";
@@ -349,6 +343,7 @@ public class ApiConstants {
349343
public static final String MAX_BACKUPS = "maxbackups";
350344
public static final String MAX_CPU_NUMBER = "maxcpunumber";
351345
public static final String MAX_MEMORY = "maxmemory";
346+
public static final String MESSAGE = "message";
352347
public static final String MIN_CPU_NUMBER = "mincpunumber";
353348
public static final String MIN_MEMORY = "minmemory";
354349
public static final String MIGRATION_TYPE = "migrationtype";
@@ -521,6 +516,7 @@ public class ApiConstants {
521516
public static final String POD_STORAGE_ACCESS_GROUPS = "podstorageaccessgroups";
522517
public static final String ZONE_STORAGE_ACCESS_GROUPS = "zonestorageaccessgroups";
523518
public static final String SUCCESS = "success";
519+
public static final String SUCCESS_MESSAGE = "successmessage";
524520
public static final String SUITABLE_FOR_VM = "suitableforvirtualmachine";
525521
public static final String SUPPORTS_STORAGE_SNAPSHOT = "supportsstoragesnapshot";
526522
public static final String TARGET_IQN = "targetiqn";
@@ -683,7 +679,7 @@ public class ApiConstants {
683679
public static final String PROJECT_ROLE_NAME = "projectrolename";
684680
public static final String ROLE_TYPE = "roletype";
685681
public static final String ROLE_NAME = "rolename";
686-
public static final String ROLES_LIST = "roleslist";
682+
public static final String ROLES = "roles";
687683
public static final String PERMISSION = "permission";
688684
public static final String RULE = "rule";
689685
public static final String RULES = "rules";

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717

1818
package org.apache.cloudstack.api.response;
1919

20-
import org.apache.cloudstack.extension.ExtensionCustomAction;
21-
import com.cloud.serializer.Param;
22-
import com.google.gson.annotations.SerializedName;
20+
import java.util.Date;
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.Set;
24+
2325
import org.apache.cloudstack.api.ApiConstants;
2426
import org.apache.cloudstack.api.BaseResponse;
2527
import org.apache.cloudstack.api.EntityReference;
28+
import org.apache.cloudstack.extension.ExtensionCustomAction;
2629

27-
import java.util.Date;
28-
import java.util.Map;
29-
import java.util.Set;
30+
import com.cloud.serializer.Param;
31+
import com.google.gson.annotations.SerializedName;
3032

3133
@EntityReference(value = ExtensionCustomAction.class)
3234
public class ExtensionCustomActionResponse extends BaseResponse {
@@ -55,9 +57,17 @@ public class ExtensionCustomActionResponse extends BaseResponse {
5557
@Param(description = "Resource type for which the action is available")
5658
private String resourceType;
5759

58-
@SerializedName(ApiConstants.ROLES_LIST)
59-
@Param(description = "Comma separated list of roles associated with the extension custom action")
60-
private String rolesList;
60+
@SerializedName(ApiConstants.ROLES)
61+
@Param(description = "List of roles associated with the extension custom action")
62+
private List<String> roles;
63+
64+
@SerializedName(ApiConstants.SUCCESS_MESSAGE)
65+
@Param(description = "Message that will be used on successful execution of the action")
66+
private String successMessage;
67+
68+
@SerializedName(ApiConstants.ERROR_MESSAGE)
69+
@Param(description = "Message that will be used on failure during execution of the action")
70+
private String errorMessage;
6171

6272
@SerializedName(ApiConstants.ENABLED)
6373
@Param(description = "Whether the extension custom action is enabled or not")
@@ -75,11 +85,10 @@ public class ExtensionCustomActionResponse extends BaseResponse {
7585
@Param(description = "Creation timestamp of the extension custom action")
7686
private Date created;
7787

78-
public ExtensionCustomActionResponse(String id, String name, String description, String rolesList) {
88+
public ExtensionCustomActionResponse(String id, String name, String description) {
7989
this.id = id;
8090
this.name = name;
8191
this.description = description;
82-
this.rolesList = rolesList;
8392
}
8493

8594
public String getId() {
@@ -122,12 +131,20 @@ public void setResourceType(String resourceType) {
122131
this.resourceType = resourceType;
123132
}
124133

125-
public String getRolesList() {
126-
return rolesList;
134+
public List<String> getRoles() {
135+
return roles;
136+
}
137+
138+
public void setRoles(List<String> roles) {
139+
this.roles = roles;
140+
}
141+
142+
public void setSuccessMessage(String successMessage) {
143+
this.successMessage = successMessage;
127144
}
128145

129-
public void setRolesList(String rolesList) {
130-
this.rolesList = rolesList;
146+
public void setErrorMessage(String errorMessage) {
147+
this.errorMessage = errorMessage;
131148
}
132149

133150
public void setEnabled(Boolean enabled) {

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public class ExtensionResponse extends BaseResponse {
4747
@Param(description = "Type of the extension")
4848
private String type;
4949

50-
@SerializedName(ApiConstants.SCRIPT)
51-
@Param(description = "the path of the script")
52-
private String script;
50+
@SerializedName(ApiConstants.ENTRY_POINT)
51+
@Param(description = "The path of the entry point fo the extension")
52+
private String entryPoint;
5353

5454
@SerializedName(ApiConstants.DETAILS)
55-
@Param(description = "the details of the extension")
55+
@Param(description = "The details of the extension")
5656
private Map<String, String> details;
5757

5858
@SerializedName(ApiConstants.RESOURCES)
@@ -98,12 +98,8 @@ public void setType(String type) {
9898
this.type = type;
9999
}
100100

101-
public String getScriptPath() {
102-
return script;
103-
}
104-
105-
public void setScriptPath(String script) {
106-
this.script = script;
101+
public void setEntryPoint(String entryPoint) {
102+
this.entryPoint = entryPoint;
107103
}
108104

109105
public void setDetails(Map<String, String> details) {

api/src/main/java/org/apache/cloudstack/extension/CustomActionResultResponse.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ public class CustomActionResultResponse extends BaseResponse {
3535
@Param(description = "Name of the action")
3636
private String name;
3737

38-
@SerializedName(ApiConstants.DETAILS)
39-
@Param(description = "Details of the action execution")
40-
private Map<String, String> details;
38+
@SerializedName(ApiConstants.SUCCESS)
39+
@Param(description = "Whether custom action succeed or not")
40+
private Boolean success;
41+
42+
@SerializedName(ApiConstants.RESULT1)
43+
@Param(description = "Result of the action execution")
44+
private Map<String, String> result;
4145

4246
public void setId(String id) {
4347
this.id = id;
@@ -47,7 +51,11 @@ public void setName(String name) {
4751
this.name = name;
4852
}
4953

50-
public void setDetails(Map<String, String> details) {
51-
this.details = details;
54+
public void setSuccess(Boolean success) {
55+
this.success = success;
56+
}
57+
58+
public void setResult(Map<String, String> result) {
59+
this.result = result;
5260
}
5361
}

api/src/main/java/org/apache/cloudstack/extension/Extension.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
import org.apache.cloudstack.api.InternalIdentity;
2424

2525
public interface Extension extends InternalIdentity, Identity {
26+
enum Type {
27+
Orchestrator
28+
}
2629
String getName();
2730
String getDescription();
28-
String getType();
29-
String getScript();
31+
Type getType();
32+
String getRelativeEntryPoint();
3033
Date getCreated();
3134
}

api/src/main/java/org/apache/cloudstack/extension/ExtensionCustomAction.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939

4040
public interface ExtensionCustomAction extends InternalIdentity, Identity {
4141
enum ResourceType {
42-
VirtualMachine(com.cloud.vm.VirtualMachine.class),
43-
Host(com.cloud.host.Host.class),
44-
Cluster(com.cloud.org.Cluster.class);
42+
VirtualMachine(com.cloud.vm.VirtualMachine.class);
4543

4644
private final Class<?> clazz;
4745

@@ -74,7 +72,11 @@ public static ResourceType fromString(String value) {
7472

7573
ResourceType getResourceType();
7674

77-
String getRolesList();
75+
Integer getRoles();
76+
77+
String getSuccessMessage();
78+
79+
String getErrorMessage();
7880

7981
boolean isEnabled();
8082

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,10 @@
1919

2020
package com.cloud.agent.api;
2121

22-
import java.util.HashMap;
23-
import java.util.Map;
24-
2522
public class RunCustomActionAnswer extends Answer {
2623

27-
Map<String, String> runDetails;
28-
29-
public RunCustomActionAnswer() {
30-
super();
31-
}
32-
3324
public RunCustomActionAnswer(RunCustomActionCommand cmd, boolean success, String details) {
3425
super(cmd, success, details);
35-
runDetails = new HashMap<>();
36-
runDetails.put("success", String.valueOf(success));
37-
runDetails.put("result", details);
38-
}
39-
40-
public Map<String, String> getRunDetails() {
41-
return runDetails;
42-
}
43-
44-
public void setRunDetails(Map<String, String> runDetails) {
45-
this.runDetails = runDetails;
4626
}
4727

4828
@Override

engine/components-api/src/main/java/com/cloud/hypervisor/ExternalProvisioner.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@ public interface ExternalProvisioner extends Manager {
4848
*/
4949
String getDescription();
5050

51-
String getExtensionScriptPath(String extensionName);
51+
String getExtensionEntryPoint(String relativeEntryPoint);
5252

53-
PrepareExternalProvisioningAnswer prepareExternalProvisioning(String extensionName, PrepareExternalProvisioningCommand cmd);
53+
void prepareScripts(String extensionName, String extensionRelativeEntryPoint);
5454

55-
StartAnswer startInstance(String extensionName, StartCommand cmd);
55+
PrepareExternalProvisioningAnswer prepareExternalProvisioning(String extensionName, String extensionRelativeEntryPoint, PrepareExternalProvisioningCommand cmd);
5656

57-
StopAnswer stopInstance(String extensionName, StopCommand cmd);
57+
StartAnswer startInstance(String extensionName, String extensionRelativeEntryPoint, StartCommand cmd);
5858

59-
RebootAnswer rebootInstance(String extensionName, RebootCommand cmd);
59+
StopAnswer stopInstance(String extensionName, String extensionRelativeEntryPoint, StopCommand cmd);
6060

61-
StopAnswer expungeInstance(String extensionName, StopCommand cmd);
61+
RebootAnswer rebootInstance(String extensionName, String extensionRelativeEntryPoint, RebootCommand cmd);
6262

63-
PostExternalProvisioningAnswer postSetupInstance(String extensionName, PostExternalProvisioningCommand cmd);
63+
StopAnswer expungeInstance(String extensionName, String extensionRelativeEntryPoint, StopCommand cmd);
6464

65-
Map<String, HostVmStateReportEntry> getHostVmStateReport(String extensionName, long hostId);
65+
PostExternalProvisioningAnswer postSetupInstance(String extensionName, String extensionRelativeEntryPoint, PostExternalProvisioningCommand cmd);
6666

67-
RunCustomActionAnswer runCustomAction(String extensionName, RunCustomActionCommand cmd);
67+
Map<String, HostVmStateReportEntry> getHostVmStateReport(String extensionName, String extensionRelativeEntryPoint, long hostId);
6868

69-
void prepareScripts(String extensionName);
69+
RunCustomActionAnswer runCustomAction(String extensionName, String extensionRelativeEntryPoint, RunCustomActionCommand cmd);
7070

71-
Answer checkHealth(String extensionName, CheckHealthCommand cmd);
71+
Answer checkHealth(String extensionName, String extensionRelativeEntryPoint, CheckHealthCommand cmd);
7272
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ CREATE TABLE IF NOT EXISTS `cloud`.`extension` (
9090
`name` varchar(255) NOT NULL,
9191
`description` varchar(4096),
9292
`type` varchar(255) NOT NULL,
93-
`script` varchar(2048) NOT NULL,
93+
`relative_entry_point` varchar(2048) NOT NULL,
9494
`created` datetime NOT NULL,
9595
`removed` datetime DEFAULT NULL,
9696
PRIMARY KEY (`id`)
9797
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
9898

99-
CREATE TABLE `cloud`.`extension_details` (
99+
CREATE TABLE IF NOT EXISTS `cloud`.`extension_details` (
100100
`id` bigint unsigned UNIQUE NOT NULL AUTO_INCREMENT COMMENT 'id',
101101
`extension_id` bigint unsigned NOT NULL COMMENT 'extension to which the detail is related to',
102102
`name` varchar(255) NOT NULL COMMENT 'name of the detail',
@@ -120,7 +120,7 @@ CREATE TABLE IF NOT EXISTS `cloud`.`extension_resource_map` (
120120
INDEX `idx_extension_resource` (`resource_id`, `resource_type`)
121121
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
122122

123-
CREATE TABLE `cloud`.`extension_resource_map_details` (
123+
CREATE TABLE IF NOT EXISTS `cloud`.`extension_resource_map_details` (
124124
`id` bigint unsigned UNIQUE NOT NULL AUTO_INCREMENT COMMENT 'id',
125125
`extension_resource_map_id` bigint unsigned NOT NULL COMMENT 'mapping to which the detail is related',
126126
`name` varchar(255) NOT NULL COMMENT 'name of the detail',
@@ -135,10 +135,12 @@ CREATE TABLE IF NOT EXISTS `cloud`.`extension_custom_action` (
135135
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
136136
`uuid` varchar(255) NOT NULL UNIQUE,
137137
`name` varchar(255) NOT NULL,
138-
`description` varchar(255) NOT NULL,
138+
`description` varchar(4096) NOT NULL,
139139
`extension_id` bigint(20) unsigned NOT NULL,
140140
`resource_type` varchar(255),
141141
`roles_list` varchar(255) DEFAULT NULL,
142+
`success_message` varchar(4096),
143+
`error_message` varchar(4096),
142144
`enabled` boolean DEFAULT true,
143145
`created` datetime NOT NULL,
144146
`removed` datetime DEFAULT NULL,

0 commit comments

Comments
 (0)