Skip to content

Commit 11693f3

Browse files
Locharla, SandeepLocharla, Sandeep
authored andcommitted
CSTACKEX-25: Create Volume code basic code added
1 parent aba389e commit 11693f3

File tree

10 files changed

+214
-33
lines changed

10 files changed

+214
-33
lines changed

plugins/storage/volume/ontap/pom.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@
8787
<artifactId>swagger-annotations</artifactId>
8888
<version>${swagger-annotations.version}</version>
8989
</dependency>
90-
<dependency>
91-
<groupId>org.springframework</groupId>
92-
<artifactId>spring-web</artifactId>
93-
</dependency>
94-
<dependency>
95-
<groupId>org.springframework.boot</groupId>
96-
<artifactId>spring-boot-starter</artifactId>
97-
<version>${spring-boot.version}</version>
98-
</dependency>
90+
<!-- <dependency>-->
91+
<!-- <groupId>org.springframework</groupId>-->
92+
<!-- <artifactId>spring-web</artifactId>-->
93+
<!-- </dependency>-->
94+
<!-- <dependency>-->
95+
<!-- <groupId>org.springframework.boot</groupId>-->
96+
<!-- <artifactId>spring-boot-starter</artifactId>-->
97+
<!-- <version>${spring-boot.version}</version>-->
98+
<!-- </dependency>-->
9999
</dependencies>
100100
<build>
101101
<plugins>

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/feign/model/request/VolumeRequestDTO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class VolumeRequestDTO {
2424
private String name;
2525
private List<AggregateDTO> aggregates;
2626
private SvmDTO svm;
27+
private Integer size;
2728

2829
// getters and setters
2930
public String getName() { return name; }
@@ -32,6 +33,8 @@ public class VolumeRequestDTO {
3233
public void setAggregates(List<AggregateDTO> aggregates) { this.aggregates = aggregates; }
3334
public SvmDTO getSvm() { return svm; }
3435
public void setSvm(SvmDTO svm) { this.svm = svm; }
36+
public Integer getSize() { return size; }
37+
public void setSize(Integer size) { this.size = size; }
3538

3639
public static class AggregateDTO {
3740
private String name;

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/lifecycle/OntapPrimaryDatastoreLifecycle.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ public class OntapPrimaryDatastoreLifecycle extends BasePrimaryDataStoreLifeCycl
6363
*/
6464
@Override
6565
public DataStore initialize(Map<String, Object> dsInfos) {
66-
String url = (String) dsInfos.get("url");
66+
String url = dsInfos.get("url").toString();
6767
Long zoneId = (Long) dsInfos.get("zoneId");
6868
Long podId = (Long)dsInfos.get("podId");
6969
Long clusterId = (Long)dsInfos.get("clusterId");
70-
String storagePoolName = (String)dsInfos.get("name");
71-
String providerName = (String)dsInfos.get("providerName");
72-
String tags = (String)dsInfos.get("tags");
70+
String storagePoolName = dsInfos.get("name").toString();
71+
String providerName = dsInfos.get("providerName").toString();
72+
String tags = dsInfos.get("tags").toString();
7373
Boolean isTagARule = (Boolean) dsInfos.get("isTagARule");
74-
String protocol = (String) dsInfos.get("protocol"); // TODO: Figure out the proper key for protocol
74+
String scheme = dsInfos.get("scheme").toString();
75+
7576
// Additional details requested for ONTAP primary storage pool creation
7677
@SuppressWarnings("unchecked")
7778
Map<String, String> details = (Map<String, String>)dsInfos.get("details");
@@ -100,27 +101,36 @@ public DataStore initialize(Map<String, Object> dsInfos) {
100101
parameters.setHypervisorType(clusterVO.getHypervisorType());
101102
}
102103
else {
103-
parameters.setHypervisorType(Hypervisor.HypervisorType.Any);
104+
parameters.setHypervisorType(Hypervisor.HypervisorType.Any); //TODO: Make sure the hypervisor is KVM, if not throw exception
104105
}
105106

106107
// Validate the ONTAP details
107-
StorageProviderManager storageProviderManager = new StorageProviderManager(details, protocol);
108+
StorageProviderManager storageProviderManager = new StorageProviderManager(details, scheme);
108109
boolean isValid = storageProviderManager.connect(details);
109110
//TODO: Use the return value to decide if we should proceed with pool creation
110111

111112
if (isValid) {
112-
String volumeName = storagePoolName + "_vol"; //TODO: Figure out a better naming convention
113-
storageProviderManager.createVolume(volumeName, Long.parseLong(details.get("size"))); // TODO: size should be in bytes, so see if conversion is needed
113+
// String volumeName = storagePoolName + "_vol"; //TODO: Figure out a better naming convention
114+
storageProviderManager.createVolume(storagePoolName, Integer.parseInt((details.get("size")))); // TODO: size should be in bytes, so see if conversion is needed
114115
// TODO: The volume name should be stored against the StoragePool name/id in the DB
115116
} else {
116117
s_logger.error("ONTAP details validation failed, cannot create primary storage");
117118
return null; // TODO: Figure out a better exception handling mechanism
118119
}
119120

121+
// TODO: While testing need to check what does this actually do and if the fields corresponding to each protocol should also be set
122+
if (scheme.equalsIgnoreCase("nfs")) {
123+
parameters.setType(Storage.StoragePoolType.NetworkFilesystem);
124+
} else if (scheme.equalsIgnoreCase("iscsi")) {
125+
parameters.setType(Storage.StoragePoolType.Iscsi);
126+
} else {
127+
s_logger.error("Unsupported protocol: " + scheme + ", cannot create primary storage");
128+
return null; // TODO: Figure out a better exception handling mechanism
129+
}
130+
120131
parameters.setTags(tags);
121132
parameters.setIsTagARule(isTagARule);
122133
parameters.setDetails(details);
123-
parameters.setType(Storage.StoragePoolType.Iscsi);
124134
parameters.setUuid(UUID.randomUUID().toString());
125135
parameters.setZoneId(zoneId);
126136
parameters.setPodId(podId);

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/provider/StorageProviderManager.java

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,68 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.cloudstack.storage.provider;
221

22+
import com.cloud.storage.Storage;
23+
import org.apache.cloudstack.storage.feign.client.VolumeFeignClient;
24+
import org.apache.cloudstack.storage.feign.model.Svm;
25+
import org.apache.cloudstack.storage.feign.model.request.VolumeRequestDTO;
26+
import org.apache.cloudstack.storage.feign.model.response.JobResponseDTO;
327
import org.apache.cloudstack.storage.service.NASStrategy;
428
import org.apache.cloudstack.storage.service.SANStrategy;
529
import org.apache.cloudstack.storage.service.UnifiedNASStrategy;
630
import org.apache.cloudstack.storage.service.UnifiedSANStrategy;
31+
import org.apache.cloudstack.storage.utils.Utility;
732
import org.apache.logging.log4j.LogManager;
833
import org.apache.logging.log4j.Logger;
34+
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.springframework.stereotype.Component;
936

37+
import java.util.List;
1038
import java.util.Map;
1139

40+
@Component
1241
public class StorageProviderManager {
42+
@Autowired
43+
private Utility utils;
44+
45+
@Autowired
46+
private VolumeFeignClient volumeFeignClient;
47+
1348
private final NASStrategy nasStrategy;
1449
private final SANStrategy sanStrategy;
1550
private static final Logger s_logger = (Logger) LogManager.getLogger(StorageProviderManager.class);
1651

52+
private final String username;
53+
private final String password;
54+
private final String svmName;
55+
private final String aggrName;
56+
1757
public StorageProviderManager(Map<String, String> details, String protocol) {
18-
String svmName = details.get("svmName");
19-
String username = details.get("username");
20-
if ("nfs".equalsIgnoreCase(protocol)) { // TODO: Cloudstack protocol list is different than ONTAP supported protocols, so figure out the proper mapping
58+
this.svmName = details.get("svmName");
59+
this.aggrName = details.get("aggrName");
60+
this.username = details.get("username");
61+
this.password = details.get("password");
62+
if (protocol.equalsIgnoreCase(Storage.StoragePoolType.NetworkFilesystem.name())) { // TODO: Cloudstack protocol list is different than ONTAP supported protocols, so figure out the proper mapping
2163
this.nasStrategy = new UnifiedNASStrategy(details);
2264
this.sanStrategy = null;
23-
} else if ("iscsi".equalsIgnoreCase(protocol)) { // TODO: Cloudstack protocol list is different than ONTAP supported protocols, so figure out the proper mapping
65+
} else if (protocol.equalsIgnoreCase(Storage.StoragePoolType.Iscsi.name())) { // TODO: Cloudstack protocol list is different than ONTAP supported protocols, so figure out the proper mapping
2466
this.sanStrategy = new UnifiedSANStrategy(details);
2567
this.nasStrategy = null;
2668
} else {
@@ -45,7 +87,26 @@ public boolean connect(Map<String, String> details) {
4587
}
4688

4789
// Common methods like create/delete etc., should be here
48-
public void createVolume(String volumeName, long size) {
90+
public void createVolume(String volumeName, int size) {
4991
// TODO: Call the ontap feign client for creating volume here
92+
// Get the AuthHeader
93+
String authHeader = utils.generateAuthHeader(username, password);
94+
// Call Create Volume API
95+
96+
// Generate the Create Volume Request
97+
VolumeRequestDTO volumeRequest = new VolumeRequestDTO();
98+
VolumeRequestDTO.SvmDTO svm = new VolumeRequestDTO.SvmDTO();
99+
VolumeRequestDTO.AggregateDTO aggr = new VolumeRequestDTO.AggregateDTO();
100+
svm.setName(svmName);
101+
aggr.setName(aggrName); // TODO: Get aggr list and pick the least used one
102+
103+
volumeRequest.setName(volumeName);
104+
volumeRequest.setSvm(svm);
105+
volumeRequest.setAggregates((List<VolumeRequestDTO.AggregateDTO>) aggr); //TODO: Should we accept comma separated list of aggregates in the UI?
106+
volumeRequest.setSize(size);
107+
// Make the POST API call to create the volume
108+
JobResponseDTO response = volumeFeignClient.createVolumeWithJob(authHeader, volumeRequest);
109+
110+
50111
}
51112
}

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/NASStrategy.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.cloudstack.storage.service;
221

322
public interface NASStrategy {

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/SANStrategy.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.cloudstack.storage.service;
221

322
public interface SANStrategy {

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.cloudstack.storage.service;
221

322
import java.util.Map;

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedSANStrategy.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package org.apache.cloudstack.storage.service;
221

322
import java.util.Map;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.cloudstack.storage.utils;
21+
22+
import com.cloud.utils.StringUtils;
23+
import org.springframework.stereotype.Component;
24+
import org.springframework.util.Base64Utils;
25+
26+
@Component
27+
public class Utility {
28+
private static final String BASIC = "Basic";
29+
private static final String AUTH_HEADER_COLON = ":";
30+
/**
31+
* Method generates authentication headers using storage backend credentials passed as normal string
32+
* @param username -->> username of the storage backend
33+
* @param password -->> normal decoded password of the storage backend
34+
* @return
35+
*/
36+
public String generateAuthHeader(String username, String password) {
37+
byte[] encodedBytes = Base64Utils.encode((username + AUTH_HEADER_COLON + password).getBytes());
38+
return BASIC + StringUtils.SPACE + new String(encodedBytes);
39+
}
40+
}

plugins/storage/volume/ontap/src/main/resources/openapi-v1.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)