Skip to content

Commit 0532b0f

Browse files
start loading of TOSCA profile
1 parent 5ce4846 commit 0532b0f

14 files changed

Lines changed: 364 additions & 4 deletions

File tree

debian/rules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ override_dh_auto_install:
105105
install -D plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node-add.yml $(DESTDIR)/usr/share/$(PACKAGE)-management/cks/conf/k8s-control-node-add.yml
106106
install -D plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-node.yml $(DESTDIR)/usr/share/$(PACKAGE)-management/cks/conf/k8s-node.yml
107107

108+
install -D plugins/iac/nimble/src/main/resources/tosca/profile/compute/kubernetes-cluster.yaml $(DESTDIR)/usr/share/$(PACKAGE)-management/nimble/tosca/profile/compute/kubernetes-cluster.yaml
109+
install -D plugins/iac/nimble/src/main/resources/tosca/profile/storage/volume.yaml $(DESTDIR)/usr/share/$(PACKAGE)-management/nimble/tosca/profile/storage/volume.yaml
110+
108111
# Remove configuration in /ur/share/cloudstack-management/webapps/client/WEB-INF
109112
# This should all be in /etc/cloudstack/management
110113
ln -s ../../..$(SYSCONFDIR)/$(PACKAGE)/management $(DESTDIR)/usr/share/$(PACKAGE)-management/conf

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,13 @@ CALL `cloud`.`INSERT_EXTENSION_DETAIL_IF_NOT_EXISTS`('MaaS', 'orchestratorrequir
8787

8888
CALL `cloud`.`IDEMPOTENT_DROP_UNIQUE_KEY`('counter', 'uc_counter__provider__source__value');
8989
CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`('cloud.counter', 'uc_counter__provider__source__value__removed', '(provider, source, value, removed)');
90+
91+
-- NIMBLE
92+
CREATE TABLE IF NOT EXISTS `cloud`.`iac_templates_profile` (
93+
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
94+
`uuid` VARCHAR(40) UNIQUE,
95+
`name` VARCHAR(100) NOT NULL COMMENT 'Profile''s element name.',
96+
`type` VARCHAR(100) NOT NULL COMMENT 'Profile''s element type. Valid values are: `CAPABILITY`, `RELATIONSHIP` and `NODE`.',
97+
`element_content_file_path` VARCHAR(255) NOT NULL COMMENT 'Profile''s element content file path.',
98+
PRIMARY KEY (`id`)
99+
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.apache.cloudstack.api.APICommand;
2121
import org.apache.cloudstack.api.BaseListCmd;
2222
import org.apache.cloudstack.api.response.IacResourceTypesResponse;
23-
import org.apache.cloudstack.nimble.NimbleService;
23+
import org.apache.cloudstack.service.NimbleService;
2424

2525
import javax.inject.Inject;
2626

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.iactemplatesprofile;
18+
19+
import org.apache.cloudstack.api.Identity;
20+
import org.apache.cloudstack.api.InternalIdentity;
21+
22+
public interface IacTemplatesProfile extends Identity, InternalIdentity {
23+
enum Type {
24+
CAPABILITY, RELATIONSHIP, NODE
25+
}
26+
27+
long getId();
28+
String getName();
29+
Type getType();
30+
String getElementContentFilePath();
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.iactemplatesprofile;
18+
19+
import com.cloud.utils.db.GenericDao;
20+
21+
public interface IacTemplatesProfileDao extends GenericDao<IacTemplatesProfile, Long> {
22+
23+
}
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.iactemplatesprofile;
18+
19+
import com.cloud.utils.db.GenericDaoBase;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
public class IacTemplatesProfileDaoImpl extends GenericDaoBase<IacTemplatesProfile, Long> implements IacTemplatesProfileDao {
24+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.iactemplatesprofile;
18+
19+
import javax.persistence.Column;
20+
import javax.persistence.Entity;
21+
import javax.persistence.GeneratedValue;
22+
import javax.persistence.GenerationType;
23+
import javax.persistence.Id;
24+
import javax.persistence.Table;
25+
import java.util.UUID;
26+
27+
@Entity
28+
@Table(name = "iac_templates_profile")
29+
public class IacTemplatesProfileVO implements IacTemplatesProfile {
30+
@Id
31+
@GeneratedValue(strategy = GenerationType.IDENTITY)
32+
@Column(name = "id", nullable = false)
33+
private Long id;
34+
35+
@Column(name = "uuid", nullable = false)
36+
private String uuid = UUID.randomUUID().toString();
37+
38+
@Column(name = "name", nullable = false, length = 100)
39+
private String name;
40+
41+
@Column(name = "type", nullable = false, length = 100)
42+
private IacTemplatesProfile.Type type;
43+
44+
@Column(name = "element_content_file_path", nullable = false)
45+
private String elementContentFilePath;
46+
47+
@Override
48+
public long getId() {
49+
return id;
50+
}
51+
52+
@Override
53+
public String getUuid() {
54+
return uuid;
55+
}
56+
57+
@Override
58+
public String getName() {
59+
return name;
60+
}
61+
62+
@Override
63+
public Type getType() {
64+
return type;
65+
}
66+
67+
@Override
68+
public String getElementContentFilePath() {
69+
return elementContentFilePath;
70+
}
71+
}

plugins/iac/nimble/src/main/java/org/apache/cloudstack/nimble/NimbleManagerImpl.java renamed to plugins/iac/nimble/src/main/java/org/apache/cloudstack/service/NimbleManagerImpl.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,35 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17-
package org.apache.cloudstack.nimble;
17+
package org.apache.cloudstack.service;
1818

1919
import com.cloud.utils.component.ManagerBase;
2020
import org.apache.cloudstack.api.command.ListIacResourceTypesCmd;
2121
import org.apache.cloudstack.framework.config.ConfigKey;
22+
import org.apache.cloudstack.persistence.iactemplatesprofile.IacTemplatesProfile;
23+
import org.apache.cloudstack.persistence.iactemplatesprofile.IacTemplatesProfileDao;
2224

25+
import javax.inject.Inject;
2326
import javax.naming.ConfigurationException;
27+
import java.io.IOException;
28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
30+
import java.nio.file.Paths;
2431
import java.util.ArrayList;
2532
import java.util.List;
2633
import java.util.Map;
2734
import java.util.concurrent.ExecutorService;
2835
import java.util.concurrent.Executors;
36+
import java.util.stream.Collectors;
2937

3038
public class NimbleManagerImpl extends ManagerBase implements NimbleService {
39+
@Inject
40+
private IacTemplatesProfileDao iacTemplatesProfileDao;
41+
3142
private ExecutorService nimbleExecutorPool;
3243

44+
private List<IacTemplatesProfile> toscaProfile;
45+
3346
@Override
3447
public void listIacResourceTypes() {
3548
logger.info("All set :) -> let's finish this!!!");
@@ -43,9 +56,29 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
4356
logger.debug("Configuring NIMBLE's fixed thread pool with [{}] threads.", nimbleServicePoolSize);
4457
nimbleExecutorPool = Executors.newFixedThreadPool(nimbleServicePoolSize);
4558

59+
loadToscaProfile();
60+
4661
return true;
4762
}
4863

64+
protected List<String> loadToscaProfile() {
65+
logger.info("Loading NIMBLE's TOSCA profile.");
66+
List<IacTemplatesProfile> profileElements = iacTemplatesProfileDao.listAll();
67+
return profileElements.stream().map(element -> {
68+
String elementContent = getElementDefinition(element.getElementContentFilePath());
69+
return elementContent;
70+
}).collect(Collectors.toList());
71+
}
72+
73+
protected String getElementDefinition(String resource) {
74+
Path path = Paths.get(String.format("%s%s", NIMBLE_CONFIG_PATH, "tosca/profile/storage/volume.yaml"));
75+
try {
76+
return Files.readString(path);
77+
} catch (IOException e) {
78+
return null;
79+
}
80+
}
81+
4982
@Override
5083
public boolean stop() {
5184
logger.info("Stopping NIMBLE's manager.");

plugins/iac/nimble/src/main/java/org/apache/cloudstack/nimble/NimbleService.java renamed to plugins/iac/nimble/src/main/java/org/apache/cloudstack/service/NimbleService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17-
package org.apache.cloudstack.nimble;
17+
package org.apache.cloudstack.service;
1818

1919
import com.cloud.utils.component.PluggableService;
2020
import org.apache.cloudstack.framework.config.ConfigKey;
2121
import org.apache.cloudstack.framework.config.Configurable;
2222

2323
public interface NimbleService extends PluggableService, Configurable {
24+
String NIMBLE_CONFIG_PATH = "/usr/share/cloudstack-management/nimble/";
25+
2426
ConfigKey<Boolean> NimbleServiceEnabled = new ConfigKey<>("Advanced", Boolean.class,
2527
"nimble.service.enabled", "false",
2628
"Indicates whether NIMBLE (Native IaC Management, Build & Launch Engine) is enabled.", false);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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.tosca;
18+
19+
public interface ToscaManager {
20+
}

0 commit comments

Comments
 (0)