Skip to content

Commit ba9e33d

Browse files
implementing registerIacTemplate API
1 parent 5f4603e commit ba9e33d

16 files changed

Lines changed: 355 additions & 28 deletions

File tree

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

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command;
1818

19+
import com.cloud.user.Account;
1920
import org.apache.cloudstack.acl.RoleType;
2021
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiArgValidator;
2123
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
2225
import org.apache.cloudstack.api.BaseCmd;
2326
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.response.AccountResponse;
2429
import org.apache.cloudstack.api.response.DomainResponse;
2530
import org.apache.cloudstack.api.response.IacTemplateResponse;
2631
import org.apache.cloudstack.api.response.ProjectResponse;
32+
import org.apache.cloudstack.context.CallContext;
2733
import org.apache.cloudstack.persistence.iactemplates.IacTemplate;
2834
import org.apache.cloudstack.service.NimbleService;
2935

3036
import javax.inject.Inject;
37+
import java.util.List;
3138

3239
@APICommand(name = "registerIacTemplate",
3340
description = "Register an IaC template, such as a TOSCA service template.",
@@ -37,43 +44,97 @@ public class RegisterIacTemplateCmd extends BaseCmd {
3744
@Inject
3845
private NimbleService nimbleService;
3946

40-
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The name of the IaC template.", required = true)
47+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING,
48+
description = "Name of the IaC template.", required = true, validations = {ApiArgValidator.NotNullOrEmpty})
4149
private String name;
4250

43-
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "The description of the IaC template.")
51+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "Description of the IaC template.")
4452
private String description;
4553

46-
@Parameter(name = ApiConstants.IAC_TEMPLATE_CONTENT, type = CommandType.STRING, length = 65535, description = "The content of the IaC template.", required = true)
54+
@Parameter(name = ApiConstants.IAC_TEMPLATE_CONTENT, type = CommandType.STRING, length = 65535,
55+
description = "Content of the IaC template.", required = true, validations = {ApiArgValidator.NotNullOrEmpty})
4756
private String iacTemplateContent;
4857

49-
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "ID of the domain associated with the IaC template. It must be used along with the \"account\" parameter.")
58+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class,
59+
description = "ID of the domain associated with the IaC template. It must be used along with the \"account\" parameter.")
5060
private Long domainId;
5161

52-
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "The name of the account owner of the IaC template. It must be used along with the \"domainid\" parameter.")
62+
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING,
63+
description = "Name of the account that will own the IaC template. It must be used along with the \"domainid\" parameter.")
5364
private String accountName;
5465

55-
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "ID of the project owner of the IaC template. Mutually exclusive with the \"account\" parameter.")
66+
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class,
67+
description = "ID of the project that will own the IaC template. Mutually exclusive with the \"account\" parameter.")
5668
private Long projectId;
5769

58-
@Parameter(name = ApiConstants.SHARED_DOMAIN_IDS, type = CommandType.STRING, description = "")
59-
private String sharedDomainIds;
70+
@Parameter(name = ApiConstants.SHARED_DOMAIN_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = DomainResponse.class,
71+
description = "A comma-separated list of domain IDs with which the IaC template will be shared.")
72+
private List<Long> sharedDomainIds;
6073

61-
@Parameter(name = ApiConstants.SHARED_ACCOUNT_IDS, type = CommandType.STRING, description = "")
62-
private String sharedAccountIds;
74+
@Parameter(name = ApiConstants.SHARED_ACCOUNT_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AccountResponse.class,
75+
description = "A comma-separated list of account IDs with which the IaC template will be shared.")
76+
private List<Long> sharedAccountIds;
6377

64-
@Parameter(name = ApiConstants.SHARED_PROJECT_IDS, type = CommandType.STRING, description = "")
65-
private String sharedProjectIds;
78+
@Parameter(name = ApiConstants.SHARED_PROJECT_IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = ProjectResponse.class,
79+
description = "A comma-separated list of project IDs with which the IaC template will be shared.")
80+
private List<Long> sharedProjectIds;
6681

67-
@Parameter(name = ApiConstants.RECURSIVE_DOMAINS, type = CommandType.BOOLEAN, description = "Defines whether IaC template will be shared among the subdomains of the informed domains in the \"shareddomainids\" parameter. Defaults to false.")
82+
@Parameter(name = ApiConstants.RECURSIVE_DOMAINS, type = CommandType.BOOLEAN,
83+
description = "Defines whether the IaC template will be shared with the subdomains of the domains specified in the \"shareddomainids\" parameter. Defaults to false.")
6884
private boolean recursiveDomains = false;
69-
70-
@Override
71-
public void execute() {
7285

86+
public String getName() {
87+
return name;
88+
}
89+
90+
public String getDescription() {
91+
return description;
92+
}
93+
94+
public String getIacTemplateContent() {
95+
return iacTemplateContent;
96+
}
97+
98+
public Long getDomainId() {
99+
return domainId;
100+
}
101+
102+
public String getAccountName() {
103+
return accountName;
104+
}
105+
106+
public Long getProjectId() {
107+
return projectId;
108+
}
109+
110+
public List<Long> getSharedDomainIds() {
111+
return sharedDomainIds;
112+
}
113+
114+
public List<Long> getSharedAccountIds() {
115+
return sharedAccountIds;
116+
}
117+
118+
public List<Long> getSharedProjectIds() {
119+
return sharedProjectIds;
120+
}
121+
122+
public boolean isRecursiveDomains() {
123+
return recursiveDomains;
73124
}
74125

75126
@Override
76127
public long getEntityOwnerId() {
77-
return 0;
128+
Account caller = CallContext.current().getCallingAccount();
129+
Account owner = _accountService.finalizeOwner(caller, getAccountName(), getDomainId(), getProjectId());
130+
return owner == null ? caller.getAccountId() : owner.getAccountId();
131+
}
132+
133+
@Override
134+
public void execute() {
135+
IacTemplate iacTemplate = nimbleService.registerIacTemplate(this);
136+
if (iacTemplate == null) {
137+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register IaC template.");
138+
}
78139
}
79140
}

plugins/iac/nimble/src/main/java/org/apache/cloudstack/api/response/NimbleResponseBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ public IacResourceTypeResponse createIacResourceTypeResponse(IacResourceType iac
3232
response.setObjectName("iacresourcetypes");
3333
return response;
3434
}
35+
36+
public void createIacTemplateResponse() {
37+
38+
}
3539
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.persistence.iactemplates;
18+
19+
import com.cloud.utils.db.GenericDao;
20+
21+
public interface IacTemplateAccountMapDao extends GenericDao<IacTemplateAccountMapVO, Long> {
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.persistence.iactemplates;
18+
19+
import com.cloud.utils.db.GenericDaoBase;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
public class IacTemplateAccountMapDaoImpl extends GenericDaoBase<IacTemplateAccountMapVO, Long> implements IacTemplateAccountMapDao {
24+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ public class IacTemplateAccountMapVO {
2828

2929
@Column(name = "account_id", nullable = false)
3030
private long accountId;
31+
32+
public IacTemplateAccountMapVO(long iacTemplateId, long accountId) {
33+
this.iacTemplateId = iacTemplateId;
34+
this.accountId = accountId;
35+
}
3136
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.persistence.iactemplates;
18+
19+
import com.cloud.utils.db.GenericDao;
20+
21+
public interface IacTemplateDao extends GenericDao<IacTemplateVO, Long> {
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.persistence.iactemplates;
18+
19+
import com.cloud.utils.db.GenericDaoBase;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
public class IacTemplateDaoImpl extends GenericDaoBase<IacTemplateVO, Long> implements IacTemplateDao {
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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.persistence.iactemplates;
18+
19+
import com.cloud.utils.db.GenericDao;
20+
21+
public interface IacTemplateDomainMapDao extends GenericDao<IacTemplateDomainMapVO, Long> {
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.persistence.iactemplates;
18+
19+
import com.cloud.utils.db.GenericDaoBase;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
public class IacTemplateDomainMapDaoImpl extends GenericDaoBase<IacTemplateDomainMapVO, Long> implements IacTemplateDomainMapDao {
24+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ public class IacTemplateDomainMapVO {
2828

2929
@Column(name = "domain_id", nullable = false)
3030
private long domainId;
31+
32+
public IacTemplateDomainMapVO(long iacTemplateId, long domainId) {
33+
this.iacTemplateId = iacTemplateId;
34+
this.domainId = domainId;
35+
}
3136
}

0 commit comments

Comments
 (0)