Skip to content

Commit 86546fd

Browse files
committed
wip: initial skeleton
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 7e84850 commit 86546fd

33 files changed

Lines changed: 2234 additions & 3 deletions

‎api/src/main/java/com/cloud/event/EventTypes.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ public class EventTypes {
173173
public static final String EVENT_NET_RULE_ADD = "NET.RULEADD";
174174
public static final String EVENT_NET_RULE_DELETE = "NET.RULEDELETE";
175175
public static final String EVENT_NET_RULE_MODIFY = "NET.RULEMODIFY";
176+
public static final String EVENT_INSTANCE_BOOT_GROUP_CREATE = "INSTANCE.BOOT.GROUP.CREATE";
177+
public static final String EVENT_INSTANCE_BOOT_GROUP_DELETE = "INSTANCE.BOOT.GROUP.DELETE";
178+
public static final String EVENT_INSTANCE_BOOT_GROUP_UPDATE = "INSTANCE.BOOT.GROUP.UPDATE";
179+
public static final String EVENT_INSTANCE_BOOT_GROUP_START = "INSTANCE.BOOT.GROUP.START";
180+
public static final String EVENT_INSTANCE_BOOT_GROUP_STOP = "INSTANCE.BOOT.GROUP.STOP";
181+
public static final String EVENT_INSTANCE_BOOT_GROUP_REBOOT = "INSTANCE.BOOT.GROUP.REBOOT";
182+
176183
public static final String EVENT_NETWORK_CREATE = "NETWORK.CREATE";
177184
public static final String EVENT_NETWORK_DELETE = "NETWORK.DELETE";
178185
public static final String EVENT_NETWORK_UPDATE = "NETWORK.UPDATE";

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public class ApiConstants {
9292
public static final String CAPACITY = "capacity";
9393
public static final String CATEGORY = "category";
9494
public static final String CAN_REVERT = "canrevert";
95+
public static final String BOOT_GROUP_ID = "bootgroupid";
96+
public static final String BOOT_ORDER = "order";
97+
public static final String MEMBER_TYPE = "membertype";
98+
public static final String MEMBER_ID = "memberid";
99+
public static final String MEMBER_NAME = "membername";
95100
public static final String CA_CERTIFICATES = "cacertificates";
96101
public static final String CERTIFICATE = "certificate";
97102
public static final String CERTIFICATE_CHAIN = "certchain";

‎api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ ZoneResponse createZoneResponse(ResponseView view, DataCenter dataCenter, Boolea
331331

332332
InstanceGroupResponse createInstanceGroupResponse(InstanceGroup group);
333333

334+
org.apache.cloudstack.api.response.InstanceBootGroupResponse createInstanceBootGroupResponse(org.apache.cloudstack.vm.bootgroup.InstanceBootGroup group);
335+
336+
org.apache.cloudstack.api.response.InstanceBootGroupMemberResponse createInstanceBootGroupMemberResponse(org.apache.cloudstack.vm.bootgroup.InstanceBootGroupMember member);
337+
334338
StoragePoolResponse createStoragePoolResponse(StoragePool pool);
335339

336340
StoragePoolResponse createStoragePoolForMigrationResponse(StoragePool pool);
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.command.user.bootgroup;
19+
20+
import javax.inject.Inject;
21+
22+
import org.apache.cloudstack.acl.RoleType;
23+
import org.apache.cloudstack.api.APICommand;
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.ApiErrorCode;
26+
import org.apache.cloudstack.api.BaseCmd;
27+
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.ServerApiException;
29+
import org.apache.cloudstack.api.command.user.UserCmd;
30+
import org.apache.cloudstack.api.response.InstanceBootGroupMemberResponse;
31+
import org.apache.cloudstack.api.response.InstanceBootGroupResponse;
32+
import org.apache.cloudstack.api.response.InstanceGroupResponse;
33+
import org.apache.cloudstack.api.response.UserVmResponse;
34+
import org.apache.cloudstack.context.CallContext;
35+
import org.apache.cloudstack.vm.bootgroup.InstanceBootGroupMember;
36+
import org.apache.cloudstack.vm.bootgroup.InstanceBootGroupService;
37+
38+
@APICommand(name = "addMemberToInstanceBootGroup",
39+
description = "Adds a VM or instance group to an instance boot group. Exactly one of virtualmachineid or instancegroupid must be specified.",
40+
responseObject = InstanceBootGroupMemberResponse.class,
41+
entityType = {InstanceBootGroupMember.class},
42+
requestHasSensitiveInfo = false,
43+
responseHasSensitiveInfo = false,
44+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
45+
public class AddMemberToInstanceBootGroupCmd extends BaseCmd implements UserCmd {
46+
47+
@Inject
48+
InstanceBootGroupService instanceBootGroupService;
49+
50+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = InstanceBootGroupResponse.class, required = true, description = "The ID of the instance boot group")
51+
private String id;
52+
53+
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, entityType = UserVmResponse.class, description = "The ID of the VM to add (exclusive with instancegroupid)")
54+
private String virtualMachineId;
55+
56+
@Parameter(name = ApiConstants.GROUP_ID, type = CommandType.UUID, entityType = InstanceGroupResponse.class, description = "The ID of the instance group to add (exclusive with virtualmachineid)")
57+
private String instanceGroupId;
58+
59+
@Parameter(name = ApiConstants.BOOT_ORDER, type = CommandType.INTEGER, required = true, description = "The boot order value for this member (0 or greater; non-contiguous values are allowed)")
60+
private int order;
61+
62+
public String getId() {
63+
return id;
64+
}
65+
66+
public String getVirtualMachineId() {
67+
return virtualMachineId;
68+
}
69+
70+
public String getInstanceGroupId() {
71+
return instanceGroupId;
72+
}
73+
74+
public int getOrder() {
75+
return order;
76+
}
77+
78+
@Override
79+
public long getEntityOwnerId() {
80+
return CallContext.current().getCallingAccount().getId();
81+
}
82+
83+
@Override
84+
public void execute() {
85+
InstanceBootGroupMember result = instanceBootGroupService.addMemberToInstanceBootGroup(this);
86+
if (result == null) {
87+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add member to instance boot group");
88+
}
89+
InstanceBootGroupMemberResponse response = _responseGenerator.createInstanceBootGroupMemberResponse(result);
90+
response.setResponseName(getCommandName());
91+
setResponseObject(response);
92+
}
93+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.command.user.bootgroup;
19+
20+
import javax.inject.Inject;
21+
22+
import org.apache.cloudstack.acl.RoleType;
23+
import org.apache.cloudstack.api.APICommand;
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.ApiErrorCode;
26+
import org.apache.cloudstack.api.BaseCmd;
27+
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.ServerApiException;
29+
import org.apache.cloudstack.api.command.user.UserCmd;
30+
import org.apache.cloudstack.api.response.DomainResponse;
31+
import org.apache.cloudstack.api.response.InstanceBootGroupResponse;
32+
import org.apache.cloudstack.api.response.ProjectResponse;
33+
import org.apache.cloudstack.context.CallContext;
34+
import org.apache.cloudstack.vm.bootgroup.InstanceBootGroup;
35+
import org.apache.cloudstack.vm.bootgroup.InstanceBootGroupService;
36+
37+
@APICommand(name = "createInstanceBootGroup",
38+
description = "Creates an instance boot group",
39+
responseObject = InstanceBootGroupResponse.class,
40+
entityType = {InstanceBootGroup.class},
41+
requestHasSensitiveInfo = false,
42+
responseHasSensitiveInfo = false,
43+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
44+
public class CreateInstanceBootGroupCmd extends BaseCmd implements UserCmd {
45+
46+
@Inject
47+
InstanceBootGroupService instanceBootGroupService;
48+
49+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "The name of the instance boot group")
50+
private String name;
51+
52+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "The description of the instance boot group")
53+
private String description;
54+
55+
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "The account of the instance boot group. Must be used with domainId.")
56+
private String accountName;
57+
58+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "The domain ID of the account owning the instance boot group")
59+
private Long domainId;
60+
61+
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "The project of the instance boot group")
62+
private Long projectId;
63+
64+
public String getName() {
65+
return name;
66+
}
67+
68+
public String getDescription() {
69+
return description;
70+
}
71+
72+
public String getAccountName() {
73+
return accountName;
74+
}
75+
76+
public Long getDomainId() {
77+
return domainId;
78+
}
79+
80+
public Long getProjectId() {
81+
return projectId;
82+
}
83+
84+
@Override
85+
public long getEntityOwnerId() {
86+
Long accountId = _accountService.finalizeAccountId(accountName, domainId, projectId, true);
87+
if (accountId == null) {
88+
return CallContext.current().getCallingAccount().getId();
89+
}
90+
return accountId;
91+
}
92+
93+
@Override
94+
public void execute() {
95+
InstanceBootGroup result = instanceBootGroupService.createInstanceBootGroup(this);
96+
if (result == null) {
97+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create instance boot group");
98+
}
99+
InstanceBootGroupResponse response = _responseGenerator.createInstanceBootGroupResponse(result);
100+
response.setResponseName(getCommandName());
101+
setResponseObject(response);
102+
}
103+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.command.user.bootgroup;
19+
20+
import javax.inject.Inject;
21+
22+
import org.apache.cloudstack.acl.RoleType;
23+
import org.apache.cloudstack.api.APICommand;
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.ApiErrorCode;
26+
import org.apache.cloudstack.api.BaseCmd;
27+
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.ServerApiException;
29+
import org.apache.cloudstack.api.command.user.UserCmd;
30+
import org.apache.cloudstack.api.response.InstanceBootGroupResponse;
31+
import org.apache.cloudstack.api.response.SuccessResponse;
32+
import org.apache.cloudstack.context.CallContext;
33+
import org.apache.cloudstack.vm.bootgroup.InstanceBootGroup;
34+
import org.apache.cloudstack.vm.bootgroup.InstanceBootGroupService;
35+
36+
@APICommand(name = "deleteInstanceBootGroup",
37+
description = "Deletes an instance boot group",
38+
responseObject = SuccessResponse.class,
39+
entityType = {InstanceBootGroup.class},
40+
requestHasSensitiveInfo = false,
41+
responseHasSensitiveInfo = false,
42+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
43+
public class DeleteInstanceBootGroupCmd extends BaseCmd implements UserCmd {
44+
45+
@Inject
46+
InstanceBootGroupService instanceBootGroupService;
47+
48+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = InstanceBootGroupResponse.class, required = true, description = "The ID of the instance boot group")
49+
private String id;
50+
51+
public String getId() {
52+
return id;
53+
}
54+
55+
@Override
56+
public long getEntityOwnerId() {
57+
return CallContext.current().getCallingAccount().getId();
58+
}
59+
60+
@Override
61+
public void execute() {
62+
boolean result = instanceBootGroupService.deleteInstanceBootGroup(this);
63+
if (!result) {
64+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete instance boot group");
65+
}
66+
SuccessResponse response = new SuccessResponse(getCommandName());
67+
setResponseObject(response);
68+
}
69+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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.command.user.bootgroup;
19+
20+
import java.util.List;
21+
22+
import javax.inject.Inject;
23+
24+
import org.apache.cloudstack.acl.RoleType;
25+
import org.apache.cloudstack.api.APICommand;
26+
import org.apache.cloudstack.api.ApiConstants;
27+
import org.apache.cloudstack.api.BaseListCmd;
28+
import org.apache.cloudstack.api.Parameter;
29+
import org.apache.cloudstack.api.command.user.UserCmd;
30+
import org.apache.cloudstack.api.response.InstanceBootGroupMemberResponse;
31+
import org.apache.cloudstack.api.response.InstanceBootGroupResponse;
32+
import org.apache.cloudstack.api.response.ListResponse;
33+
import org.apache.cloudstack.vm.bootgroup.InstanceBootGroupMember;
34+
import org.apache.cloudstack.vm.bootgroup.InstanceBootGroupService;
35+
36+
import com.cloud.utils.Pair;
37+
38+
@APICommand(name = "listInstanceBootGroupMembers",
39+
description = "Lists members of an instance boot group, sorted by boot order",
40+
responseObject = InstanceBootGroupMemberResponse.class,
41+
entityType = {InstanceBootGroupMember.class},
42+
requestHasSensitiveInfo = false,
43+
responseHasSensitiveInfo = false,
44+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
45+
public class ListInstanceBootGroupMembersCmd extends BaseListCmd implements UserCmd {
46+
47+
@Inject
48+
InstanceBootGroupService instanceBootGroupService;
49+
50+
@Parameter(name = ApiConstants.BOOT_GROUP_ID, type = CommandType.STRING, required = true, entityType = InstanceBootGroupResponse.class, description = "The ID of the instance boot group")
51+
private String bootGroupId;
52+
53+
@Parameter(name = ApiConstants.MEMBER_TYPE, type = CommandType.STRING, description = "Filter by member type: VirtualMachine or InstanceGroup")
54+
private String memberType;
55+
56+
public String getBootGroupId() {
57+
return bootGroupId;
58+
}
59+
60+
public String getMemberType() {
61+
return memberType;
62+
}
63+
64+
@Override
65+
public void execute() {
66+
Pair<List<? extends InstanceBootGroupMember>, Integer> result = instanceBootGroupService.listInstanceBootGroupMembers(this);
67+
ListResponse<InstanceBootGroupMemberResponse> response = new ListResponse<>();
68+
List<InstanceBootGroupMemberResponse> responses = result.first().stream()
69+
.map(m -> _responseGenerator.createInstanceBootGroupMemberResponse(m))
70+
.collect(java.util.stream.Collectors.toList());
71+
response.setResponses(responses, result.second());
72+
response.setResponseName(getCommandName());
73+
setResponseObject(response);
74+
}
75+
}

0 commit comments

Comments
 (0)