Skip to content

Commit 5f4603e

Browse files
implement DB schema and start implementing registerIacTemplate API
1 parent 22fb493 commit 5f4603e

8 files changed

Lines changed: 357 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,10 @@ public class ApiConstants {
13321332
public static final String INPUTS = "inputs";
13331333
public static final String IAC_RESOURCE_TYPE_CONTENT = "iacresourcetypecontent";
13341334
public static final String SHOW_IAC_RESOURCE_TYPE_CONTENT = "showiacresourcetypecontent";
1335+
public static final String IAC_TEMPLATE_CONTENT = "iactemplatecontent";
1336+
public static final String SHARED_DOMAIN_IDS = "shareddomainids";
1337+
public static final String SHARED_ACCOUNT_IDS = "sharedaccountids";
1338+
public static final String SHARED_PROJECT_IDS = "sharedprojectids";
13351339

13361340
public static final String PARAMETER_DESCRIPTION_ACTIVATION_RULE = "Quota tariff's activation rule. It can receive a JS script that results in either " +
13371341
"a boolean or a numeric value: if it results in a boolean value, the tariff value will be applied according to the result; if it results in a numeric value, the " +

engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,35 @@ CREATE TABLE IF NOT EXISTS `cloud`.`iac_resource_types` (
2929
`content` TEXT NOT NULL COMMENT 'Profile''s element content.',
3030
PRIMARY KEY (`id`)
3131
);
32+
33+
CREATE TABLE IF NOT EXISTS `cloud`.`iac_templates` (
34+
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
35+
`uuid` VARCHAR(40) NOT NULL UNIQUE,
36+
`name` VARCHAR(2048) NOT NULL,
37+
`description` VARCHAR(4096),
38+
`iac_template_content` TEXT NOT NULL,
39+
`recursive_domains` TINYINT(1) NOT NULL DEFAULT 0,
40+
`domain_id` BIGINT(20) UNSIGNED NOT NULL,
41+
`account_id` BIGINT(20) UNSIGNED NOT NULL,
42+
`created` DATETIME NOT NULL,
43+
`removed` DATETIME,
44+
PRIMARY KEY (`id`),
45+
CONSTRAINT `fk_iac_templates__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`),
46+
CONSTRAINT `fk_iac_templates__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`)
47+
);
48+
49+
CREATE TABLE IF NOT EXISTS `cloud`.`iac_template_account_map` (
50+
`iac_template_id` BIGINT(20) UNSIGNED NOT NULL,
51+
`account_id` BIGINT(20) UNSIGNED NOT NULL,
52+
PRIMARY KEY (`iac_template_id`, `account_id`),
53+
CONSTRAINT `fk_iac_template_account_map__iac_template_id` FOREIGN KEY (`iac_template_id`) REFERENCES `iac_templates`(`id`),
54+
CONSTRAINT `fk_iac_template_account_map__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`)
55+
);
56+
57+
CREATE TABLE IF NOT EXISTS `cloud`.`iac_template_domain_map` (
58+
`iac_template_id` BIGINT(20) UNSIGNED NOT NULL,
59+
`domain_id` BIGINT(20) UNSIGNED NOT NULL,
60+
PRIMARY KEY (`iac_template_id`, `domain_id`),
61+
CONSTRAINT `fk_iac_template_domain_map__iac_template_id` FOREIGN KEY (`iac_template_id`) REFERENCES `iac_templates`(`id`),
62+
CONSTRAINT `fk_iac_template_domain_map__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`)
63+
);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.acl.RoleType;
20+
import org.apache.cloudstack.api.APICommand;
21+
import org.apache.cloudstack.api.ApiConstants;
22+
import org.apache.cloudstack.api.BaseCmd;
23+
import org.apache.cloudstack.api.Parameter;
24+
import org.apache.cloudstack.api.response.DomainResponse;
25+
import org.apache.cloudstack.api.response.IacTemplateResponse;
26+
import org.apache.cloudstack.api.response.ProjectResponse;
27+
import org.apache.cloudstack.persistence.iactemplates.IacTemplate;
28+
import org.apache.cloudstack.service.NimbleService;
29+
30+
import javax.inject.Inject;
31+
32+
@APICommand(name = "registerIacTemplate",
33+
description = "Register an IaC template, such as a TOSCA service template.",
34+
responseObject = IacTemplateResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
35+
entityType = {IacTemplate.class}, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
36+
public class RegisterIacTemplateCmd extends BaseCmd {
37+
@Inject
38+
private NimbleService nimbleService;
39+
40+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The name of the IaC template.", required = true)
41+
private String name;
42+
43+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "The description of the IaC template.")
44+
private String description;
45+
46+
@Parameter(name = ApiConstants.IAC_TEMPLATE_CONTENT, type = CommandType.STRING, length = 65535, description = "The content of the IaC template.", required = true)
47+
private String iacTemplateContent;
48+
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.")
50+
private Long domainId;
51+
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.")
53+
private String accountName;
54+
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.")
56+
private Long projectId;
57+
58+
@Parameter(name = ApiConstants.SHARED_DOMAIN_IDS, type = CommandType.STRING, description = "")
59+
private String sharedDomainIds;
60+
61+
@Parameter(name = ApiConstants.SHARED_ACCOUNT_IDS, type = CommandType.STRING, description = "")
62+
private String sharedAccountIds;
63+
64+
@Parameter(name = ApiConstants.SHARED_PROJECT_IDS, type = CommandType.STRING, description = "")
65+
private String sharedProjectIds;
66+
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.")
68+
private boolean recursiveDomains = false;
69+
70+
@Override
71+
public void execute() {
72+
73+
}
74+
75+
@Override
76+
public long getEntityOwnerId() {
77+
return 0;
78+
}
79+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.response;
18+
19+
import org.apache.cloudstack.api.BaseResponse;
20+
import org.apache.cloudstack.api.EntityReference;
21+
import org.apache.cloudstack.persistence.iactemplates.IacTemplate;
22+
23+
@EntityReference(value = {IacTemplate.class})
24+
public class IacTemplateResponse extends BaseResponse {
25+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 org.apache.cloudstack.acl.ControlledEntity;
20+
import org.apache.cloudstack.api.Identity;
21+
import org.apache.cloudstack.api.InternalIdentity;
22+
23+
import java.util.Date;
24+
25+
public interface IacTemplate extends InternalIdentity, Identity, ControlledEntity {
26+
String getName();
27+
String getDescription();
28+
String getIacTemplateContent();
29+
boolean isRecursiveDomains();
30+
Date getCreated();
31+
Date getRemoved();
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 javax.persistence.Column;
20+
import javax.persistence.Entity;
21+
import javax.persistence.Table;
22+
23+
@Entity
24+
@Table(name = "iac_template_account_map")
25+
public class IacTemplateAccountMapVO {
26+
@Column(name = "iac_template_id", nullable = false)
27+
private long iacTemplateId;
28+
29+
@Column(name = "account_id", nullable = false)
30+
private long accountId;
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 javax.persistence.Column;
20+
import javax.persistence.Entity;
21+
import javax.persistence.Table;
22+
23+
@Entity
24+
@Table(name = "iac_template_domain_map")
25+
public class IacTemplateDomainMapVO {
26+
@Column(name = "iac_template_id", nullable = false)
27+
private long iacTemplateId;
28+
29+
@Column(name = "domain_id", nullable = false)
30+
private long domainId;
31+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
import javax.persistence.Column;
22+
import javax.persistence.Entity;
23+
import javax.persistence.GeneratedValue;
24+
import javax.persistence.GenerationType;
25+
import javax.persistence.Id;
26+
import javax.persistence.Table;
27+
import javax.persistence.Temporal;
28+
import javax.persistence.TemporalType;
29+
import java.util.Date;
30+
import java.util.UUID;
31+
32+
@Entity
33+
@Table(name = "iac_templates")
34+
public class IacTemplateVO implements IacTemplate {
35+
@Id
36+
@GeneratedValue(strategy = GenerationType.IDENTITY)
37+
@Column(name = "id", nullable = false)
38+
private Long id;
39+
40+
@Column(name = "uuid", nullable = false)
41+
private String uuid = UUID.randomUUID().toString();
42+
43+
@Column(name = "name", nullable = false, length = 2048)
44+
private String name;
45+
46+
@Column(name = "description", length = 4096)
47+
private String description;
48+
49+
@Column(name = "iac_template_content", nullable = false, length = 65535)
50+
private String iacTemplateContent;
51+
52+
@Column(name = "recursive_domains", nullable = false)
53+
private boolean recursiveDomains;
54+
55+
@Column(name = "domain_id", nullable = false)
56+
private long domainId;
57+
58+
@Column(name = "account_id", nullable = false)
59+
private long accountId;
60+
61+
@Column(name = GenericDao.CREATED_COLUMN, nullable = false)
62+
@Temporal(value = TemporalType.TIMESTAMP)
63+
private Date created;
64+
65+
@Column(name = GenericDao.REMOVED_COLUMN)
66+
@Temporal(value = TemporalType.TIMESTAMP)
67+
private Date removed;
68+
69+
@Override
70+
public long getId() {
71+
return id;
72+
}
73+
74+
@Override
75+
public String getUuid() {
76+
return uuid;
77+
}
78+
79+
@Override
80+
public String getName() {
81+
return name;
82+
}
83+
84+
@Override
85+
public String getDescription() {
86+
return description;
87+
}
88+
89+
@Override
90+
public String getIacTemplateContent() {
91+
return iacTemplateContent;
92+
}
93+
94+
@Override
95+
public boolean isRecursiveDomains() {
96+
return recursiveDomains;
97+
}
98+
99+
@Override
100+
public long getDomainId() {
101+
return domainId;
102+
}
103+
104+
@Override
105+
public long getAccountId() {
106+
return accountId;
107+
}
108+
109+
@Override
110+
public Date getCreated() {
111+
return created;
112+
}
113+
114+
@Override
115+
public Date getRemoved() {
116+
return removed;
117+
}
118+
119+
@Override
120+
public Class<?> getEntityType() {
121+
return IacTemplate.class;
122+
}
123+
}

0 commit comments

Comments
 (0)