Skip to content

Commit fcff99c

Browse files
implementing updateIacTemplate API
1 parent 1007907 commit fcff99c

6 files changed

Lines changed: 247 additions & 90 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.api.command;
18+
19+
import org.apache.cloudstack.api.ApiConstants;
20+
import org.apache.cloudstack.api.BaseCmd;
21+
import org.apache.cloudstack.api.Parameter;
22+
import org.apache.cloudstack.api.response.AccountResponse;
23+
import org.apache.cloudstack.api.response.DomainResponse;
24+
import org.apache.cloudstack.api.response.ProjectResponse;
25+
import org.apache.cloudstack.service.NimbleService;
26+
27+
import javax.inject.Inject;
28+
import java.util.ArrayList;
29+
import java.util.List;
30+
31+
public abstract class BaseIacTemplateRegistrationCmd extends BaseCmd {
32+
@Inject
33+
protected NimbleService nimbleService;
34+
35+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "Name of the IaC template.")
36+
private String name;
37+
38+
@Parameter(name = ApiConstants.IAC_TEMPLATE_CONTENT, type = CommandType.STRING, length = 65535, description = "Content of the IaC template.")
39+
private String iacTemplateContent;
40+
41+
@Parameter(name = ApiConstants.SHARED_DOMAIN_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = DomainResponse.class,
42+
description = "A comma-separated list of domain IDs with which the IaC template will be shared.")
43+
private List<Long> sharedDomainIds;
44+
45+
@Parameter(name = ApiConstants.SHARED_ACCOUNT_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AccountResponse.class,
46+
description = "A comma-separated list of account IDs with which the IaC template will be shared.")
47+
private List<Long> sharedAccountIds;
48+
49+
@Parameter(name = ApiConstants.SHARED_PROJECT_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = ProjectResponse.class,
50+
description = "A comma-separated list of project IDs with which the IaC template will be shared.")
51+
private List<Long> sharedProjectIds;
52+
53+
@Parameter(name = ApiConstants.RECURSIVE_DOMAINS, type = CommandType.BOOLEAN,
54+
description = "Defines whether the IaC template will be shared with the subdomains of the domains specified in the \"shareddomainids\" parameter. Defaults to false.")
55+
private Boolean recursiveDomains;
56+
57+
public String getName() {
58+
return name;
59+
}
60+
61+
public String getIacTemplateContent() {
62+
return iacTemplateContent;
63+
}
64+
65+
public boolean isTemplateShared() {
66+
return sharedDomainIds != null || sharedAccountIds != null || sharedProjectIds != null;
67+
}
68+
69+
public List<Long> getSharedDomainIds() {
70+
return sharedDomainIds;
71+
}
72+
73+
public List<Long> getSharedAccountIds() {
74+
return sharedAccountIds;
75+
}
76+
77+
public List<Long> getSharedProjectIds() {
78+
if (sharedProjectIds == null) {
79+
return new ArrayList<>();
80+
}
81+
return sharedProjectIds;
82+
}
83+
84+
public Boolean isRecursiveDomains() {
85+
return recursiveDomains;
86+
}
87+
}

plugins/iac/nimble/src/main/java/org/apache/cloudstack/api/command/RegisterIacTemplateCmd.java

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,22 @@
1919
import com.cloud.user.Account;
2020
import org.apache.cloudstack.acl.RoleType;
2121
import org.apache.cloudstack.api.APICommand;
22-
import org.apache.cloudstack.api.ApiArgValidator;
2322
import org.apache.cloudstack.api.ApiConstants;
24-
import org.apache.cloudstack.api.BaseCmd;
2523
import org.apache.cloudstack.api.Parameter;
26-
import org.apache.cloudstack.api.response.AccountResponse;
2724
import org.apache.cloudstack.api.response.DomainResponse;
2825
import org.apache.cloudstack.api.response.IacTemplateResponse;
2926
import org.apache.cloudstack.api.response.ProjectResponse;
3027
import org.apache.cloudstack.context.CallContext;
3128
import org.apache.cloudstack.persistence.iactemplates.IacTemplate;
32-
import org.apache.cloudstack.service.NimbleService;
33-
34-
import javax.inject.Inject;
35-
import java.util.ArrayList;
36-
import java.util.List;
3729

3830
@APICommand(name = "registerIacTemplate",
3931
description = "Registers an IaC template, such as a TOSCA service template.",
4032
responseObject = IacTemplateResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
4133
entityType = {IacTemplate.class}, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
42-
public class RegisterIacTemplateCmd extends BaseCmd {
43-
@Inject
44-
private NimbleService nimbleService;
45-
46-
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING,
47-
description = "Name of the IaC template.", required = true, validations = {ApiArgValidator.NotNullOrEmpty})
48-
private String name;
49-
34+
public class RegisterIacTemplateCmd extends BaseIacTemplateRegistrationCmd {
5035
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "Description of the IaC template.")
5136
private String description;
5237

53-
@Parameter(name = ApiConstants.IAC_TEMPLATE_CONTENT, type = CommandType.STRING, length = 65535,
54-
description = "Content of the IaC template.", required = true, validations = {ApiArgValidator.NotNullOrEmpty})
55-
private String iacTemplateContent;
56-
5738
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class,
5839
description = "ID of the domain associated with the IaC template. It must be used along with the \"account\" parameter.")
5940
private Long domainId;
@@ -66,34 +47,10 @@ public class RegisterIacTemplateCmd extends BaseCmd {
6647
description = "ID of the project that will own the IaC template. Mutually exclusive with the \"account\" parameter.")
6748
private Long projectId;
6849

69-
@Parameter(name = ApiConstants.SHARED_DOMAIN_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = DomainResponse.class,
70-
description = "A comma-separated list of domain IDs with which the IaC template will be shared.")
71-
private List<Long> sharedDomainIds;
72-
73-
@Parameter(name = ApiConstants.SHARED_ACCOUNT_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AccountResponse.class,
74-
description = "A comma-separated list of account IDs with which the IaC template will be shared.")
75-
private List<Long> sharedAccountIds;
76-
77-
@Parameter(name = ApiConstants.SHARED_PROJECT_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = ProjectResponse.class,
78-
description = "A comma-separated list of project IDs with which the IaC template will be shared.")
79-
private List<Long> sharedProjectIds;
80-
81-
@Parameter(name = ApiConstants.RECURSIVE_DOMAINS, type = CommandType.BOOLEAN,
82-
description = "Defines whether the IaC template will be shared with the subdomains of the domains specified in the \"shareddomainids\" parameter. Defaults to false.")
83-
private boolean recursiveDomains = false;
84-
85-
public String getName() {
86-
return name;
87-
}
88-
8950
public String getDescription() {
9051
return description;
9152
}
9253

93-
public String getIacTemplateContent() {
94-
return iacTemplateContent;
95-
}
96-
9754
public Long getDomainId() {
9855
return domainId;
9956
}
@@ -106,35 +63,6 @@ public Long getProjectId() {
10663
return projectId;
10764
}
10865

109-
public boolean isTemplateShared() {
110-
return sharedDomainIds != null || sharedAccountIds != null || sharedProjectIds != null;
111-
}
112-
113-
public List<Long> getSharedDomainIds() {
114-
if (sharedDomainIds == null) {
115-
return new ArrayList<>();
116-
}
117-
return sharedDomainIds;
118-
}
119-
120-
public List<Long> getSharedAccountIds() {
121-
if (sharedAccountIds == null) {
122-
return new ArrayList<>();
123-
}
124-
return sharedAccountIds;
125-
}
126-
127-
public List<Long> getSharedProjectIds() {
128-
if (sharedProjectIds == null) {
129-
return new ArrayList<>();
130-
}
131-
return sharedProjectIds;
132-
}
133-
134-
public boolean isRecursiveDomains() {
135-
return recursiveDomains;
136-
}
137-
13866
@Override
13967
public long getEntityOwnerId() {
14068
Account caller = CallContext.current().getCallingAccount();
@@ -144,7 +72,7 @@ public long getEntityOwnerId() {
14472

14573
@Override
14674
public void execute() {
147-
IacTemplateResponse response = nimbleService.registerIacTemplate(this);
75+
IacTemplateResponse response = nimbleService.saveIacTemplate(this);
14876
response.setResponseName(getCommandName());
14977
setResponseObject(response);
15078
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.api.command;
18+
19+
import com.cloud.user.Account;
20+
import org.apache.cloudstack.acl.RoleType;
21+
import org.apache.cloudstack.api.ACL;
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.Parameter;
25+
import org.apache.cloudstack.api.response.IacTemplateResponse;
26+
import org.apache.cloudstack.persistence.iactemplates.IacTemplate;
27+
28+
@APICommand(name = "updateIacTemplate", description = "Updates an existing IaC template.",
29+
responseObject = IacTemplateResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
30+
entityType = {IacTemplate.class}, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
31+
public class UpdateIacTemplateCmd extends BaseIacTemplateRegistrationCmd {
32+
@ACL
33+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = IacTemplateResponse.class, required = true, description = "ID of the IaC template to be updated.")
34+
private Long id;
35+
36+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "Description of the IaC template.")
37+
private String description;
38+
39+
public Long getId() {
40+
return id;
41+
}
42+
43+
public String getDescription() {
44+
return description;
45+
}
46+
47+
@Override
48+
public void execute() {
49+
IacTemplateResponse response = nimbleService.saveIacTemplate(this);
50+
response.setResponseName(getCommandName());
51+
setResponseObject(response);
52+
}
53+
54+
@Override
55+
public long getEntityOwnerId() {
56+
IacTemplate iacTemplate = nimbleService.findIacTemplateById(id);
57+
if (iacTemplate == null) {
58+
return Account.ACCOUNT_ID_SYSTEM;
59+
}
60+
return iacTemplate.getAccountId();
61+
}
62+
}

plugins/iac/nimble/src/main/java/org/apache/cloudstack/persistence/iactemplates/IacTemplateVO.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class IacTemplateVO implements IacTemplate {
5454
private String iacTemplateContent;
5555

5656
@Column(name = "recursive_domains", nullable = false)
57-
private boolean recursiveDomains;
57+
private boolean recursiveDomains = false;
5858

5959
@Column(name = "domain_id", nullable = false)
6060
private long domainId;
@@ -103,21 +103,37 @@ public String getName() {
103103
return name;
104104
}
105105

106+
public void setName(String name) {
107+
this.name = name;
108+
}
109+
106110
@Override
107111
public String getDescription() {
108112
return description;
109113
}
110114

115+
public void setDescription(String description) {
116+
this.description = description;
117+
}
118+
111119
@Override
112120
public String getIacTemplateContent() {
113121
return iacTemplateContent;
114122
}
115123

124+
public void setIacTemplateContent(String iacTemplateContent) {
125+
this.iacTemplateContent = iacTemplateContent;
126+
}
127+
116128
@Override
117129
public boolean isRecursiveDomains() {
118130
return recursiveDomains;
119131
}
120132

133+
public void setRecursiveDomains(boolean recursiveDomains) {
134+
this.recursiveDomains = recursiveDomains;
135+
}
136+
121137
@Override
122138
public long getDomainId() {
123139
return domainId;

0 commit comments

Comments
 (0)