Skip to content

Commit 256827c

Browse files
Gupta, SuryaGupta, Surya
authored andcommitted
CSTACKEX-36 Correct the logger
1 parent d57ed07 commit 256827c

File tree

5 files changed

+53
-53
lines changed

5 files changed

+53
-53
lines changed

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/driver/OntapPrimaryDatastoreDriver.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,17 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore
192192
s_logger.error("grantAccess : Storage Pool not found for id: " + dataStore.getId());
193193
throw new CloudRuntimeException("grantAccess : Storage Pool not found for id: " + dataStore.getId());
194194
}
195-
if (storagePool.getScope() != ScopeType.CLUSTER || storagePool.getScope() != ScopeType.ZONE) {
196-
s_logger.error("grantAccess: Only Cluster and ZONE scoped primary storage is supported. Storage Pool: " + storagePool.getName());
197-
throw new CloudRuntimeException("grantAccess: Only Cluster and ZONE scoped primary storage is supported. Storage Pool: " + storagePool.getName());
198-
}
199-
200-
VolumeVO volumeVO = volumeDao.findById(dataObject.getId());
201-
if(volumeVO == null) {
202-
s_logger.error("grantAccess : Cloud Stack Volume not found for id: " + dataObject.getId());
203-
throw new CloudRuntimeException("grantAccess : Cloud Stack Volume not found for id: " + dataObject.getId());
195+
if (storagePool.getScope() != ScopeType.CLUSTER && storagePool.getScope() != ScopeType.ZONE) {
196+
s_logger.error("grantAccess: Only Cluster and ZONE scoped primary storage is supported for storage Pool: " + storagePool.getName());
197+
throw new CloudRuntimeException("grantAccess: Only Cluster and ZONE scoped primary storage is supported for Storage Pool: " + storagePool.getName());
204198
}
205199

206200
if (dataObject.getType() == DataObjectType.VOLUME) {
201+
VolumeVO volumeVO = volumeDao.findById(dataObject.getId());
202+
if(volumeVO == null) {
203+
s_logger.error("grantAccess : Cloud Stack Volume not found for id: " + dataObject.getId());
204+
throw new CloudRuntimeException("grantAccess : Cloud Stack Volume not found for id: " + dataObject.getId());
205+
}
207206
grantAccessForVolume(storagePool, volumeVO, host);
208207
} else {
209208
s_logger.error("Invalid DataObjectType (" + dataObject.getType() + ") passed to grantAccess");

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

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -181,60 +181,44 @@ public boolean attachCluster(DataStore dataStore, ClusterScope scope) {
181181
throw new InvalidParameterValueException("attachCluster: dataStore should not be null");
182182
}
183183
if (scope == null) {
184-
throw new InvalidParameterValueException("attachCluster: clusterScope should not be null");
184+
throw new InvalidParameterValueException("attachCluster: scope should not be null");
185185
}
186186
List<String> hostsIdentifier = new ArrayList<>();
187187
StoragePoolVO storagePool = storagePoolDao.findById(dataStore.getId());
188188
if(storagePool == null) {
189189
s_logger.error("attachCluster : Storage Pool not found for id: " + dataStore.getId());
190190
throw new CloudRuntimeException("attachCluster : Storage Pool not found for id: " + dataStore.getId());
191191
}
192-
PrimaryDataStoreInfo primarystore = (PrimaryDataStoreInfo)dataStore;
193-
List<HostVO> hostsToConnect = _resourceMgr.getEligibleUpAndEnabledHostsInClusterForStorageConnection(primarystore);
192+
PrimaryDataStoreInfo primaryStore = (PrimaryDataStoreInfo)dataStore;
193+
List<HostVO> hostsToConnect = _resourceMgr.getEligibleUpAndEnabledHostsInClusterForStorageConnection(primaryStore);
194194
// TODO- need to check if no host to connect then throw exception or just continue
195-
logger.debug(String.format("Attaching the pool to each of the hosts %s in the cluster: %s", hostsToConnect, primarystore.getClusterId()));
195+
logger.debug("attachCluster: Eligible Up and Enabled hosts: {} in cluster {}", hostsToConnect, primaryStore.getClusterId());
196196

197-
Map<String, String> details = primarystore.getDetails();
197+
Map<String, String> details = primaryStore.getDetails();
198198
StorageStrategy strategy = utils.getStrategyByStoragePoolDetails(details);
199199
ProtocolType protocol = ProtocolType.valueOf(details.get(Constants.PROTOCOL));
200+
//TODO- Check if we have to handle heterogeneous host within the cluster
200201
if (!isProtocolSupportedByAllHosts(hostsToConnect, protocol, hostsIdentifier)) {
201-
throw new CloudRuntimeException("Not all hosts in the cluster support the protocol: " + protocol.toString());
202+
s_logger.error("attachCluster: Not all hosts in the cluster support the protocol: " + protocol.name());
203+
throw new CloudRuntimeException("attachCluster: Not all hosts in the cluster support the protocol: " + protocol.name());
202204
}
203205
//TODO - check if no host to connect then also need to create access group without initiators
204206
if (hostsIdentifier != null && hostsIdentifier.size() > 0) {
205207
AccessGroup accessGroupRequest = utils.createAccessGroupRequestByProtocol(storagePool, scope.getScopeId(), details, hostsIdentifier);
206208
strategy.createAccessGroup(accessGroupRequest);
207209
}
210+
logger.debug("attachCluster: Attaching the pool to each of the host in the cluster: %s", primaryStore.getClusterId());
208211
for (HostVO host : hostsToConnect) {
209212
try {
210213
_storageMgr.connectHostToSharedPool(host, dataStore.getId());
211214
} catch (Exception e) {
212-
logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e);
215+
logger.warn("attachCluster: Unable to establish a connection between " + host + " and " + dataStore, e);
213216
}
214217
}
215218
_dataStoreHelper.attachCluster(dataStore);
216219
return true;
217220
}
218221

219-
private boolean isProtocolSupportedByAllHosts(List<HostVO> hosts, ProtocolType protocolType, List<String> hostIdentifiers) {
220-
String protocolPrefix;
221-
switch (protocolType) {
222-
case ISCSI:
223-
protocolPrefix = Constants.IQN;
224-
for (HostVO host : hosts) {
225-
if (host == null || host.getStorageUrl() == null || host.getStorageUrl().trim().isEmpty()
226-
|| !host.getStorageUrl().startsWith(protocolPrefix)) {
227-
return false;
228-
}
229-
hostIdentifiers.add(host.getStorageUrl());
230-
}
231-
break;
232-
default:
233-
throw new CloudRuntimeException("Unsupported protocol: " + protocolType.toString());
234-
}
235-
return true;
236-
}
237-
238222
@Override
239223
public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) {
240224
return false;
@@ -247,30 +231,31 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.Hyper
247231
throw new InvalidParameterValueException("attachZone: dataStore should not be null");
248232
}
249233
if (scope == null) {
250-
throw new InvalidParameterValueException("attachZone: clusterScope should not be null");
234+
throw new InvalidParameterValueException("attachZone: scope should not be null");
251235
}
252236
List<String> hostsIdentifier = new ArrayList<>();
253237
StoragePoolVO storagePool = storagePoolDao.findById(dataStore.getId());
254238
if(storagePool == null) {
255-
s_logger.error("attachCluster : Storage Pool not found for id: " + dataStore.getId());
239+
s_logger.error("attachZone : Storage Pool not found for id: " + dataStore.getId());
256240
throw new CloudRuntimeException("attachCluster : Storage Pool not found for id: " + dataStore.getId());
257241
}
258242
List<HostVO> hostsToConnect = _resourceMgr.getEligibleUpAndEnabledHostsInZoneForStorageConnection(dataStore, scope.getScopeId(), Hypervisor.HypervisorType.KVM);
259243
// TODO- need to check if no host to connect then throw exception or just continue
260-
logger.debug(String.format("In createPool. Attaching the pool to each of the hosts in %s.", hostsToConnect));
244+
logger.debug("attachZone: Eligible Up and Enabled hosts: {}", hostsToConnect);
261245

262246
Map<String, String> details = storagePoolDetailsDao.listDetailsKeyPairs(dataStore.getId());
263247
StorageStrategy strategy = utils.getStrategyByStoragePoolDetails(details);
264248
ProtocolType protocol = ProtocolType.valueOf(details.get(Constants.PROTOCOL));
249+
//TODO- Check if we have to handle heterogeneous host within the zone
265250
if (!isProtocolSupportedByAllHosts(hostsToConnect, protocol, hostsIdentifier)) {
266-
throw new CloudRuntimeException("Not all hosts in the zone support the protocol: " + protocol.toString());
251+
s_logger.error("attachZone: Not all hosts in the cluster support the protocol: " + protocol.name());
252+
throw new CloudRuntimeException("attachZone: Not all hosts in the zone support the protocol: " + protocol.name());
267253
}
268254
if (hostsIdentifier != null && !hostsIdentifier.isEmpty()) {
269255
AccessGroup accessGroupRequest = utils.createAccessGroupRequestByProtocol(storagePool, scope.getScopeId(), details, hostsIdentifier);
270256
strategy.createAccessGroup(accessGroupRequest);
271257
}
272258
for (HostVO host : hostsToConnect) {
273-
// TODO: Fetch the host IQN and add to the initiator group on ONTAP cluster
274259
try {
275260
_storageMgr.connectHostToSharedPool(host, dataStore.getId());
276261
} catch (Exception e) {
@@ -281,6 +266,24 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.Hyper
281266
return true;
282267
}
283268

269+
private boolean isProtocolSupportedByAllHosts(List<HostVO> hosts, ProtocolType protocolType, List<String> hostIdentifiers) {
270+
switch (protocolType) {
271+
case ISCSI:
272+
String protocolPrefix = Constants.IQN;
273+
for (HostVO host : hosts) {
274+
if (host == null || host.getStorageUrl() == null || host.getStorageUrl().trim().isEmpty()
275+
|| !host.getStorageUrl().startsWith(protocolPrefix)) {
276+
return false;
277+
}
278+
hostIdentifiers.add(host.getStorageUrl());
279+
}
280+
break;
281+
default:
282+
throw new CloudRuntimeException("isProtocolSupportedByAllHosts : Unsupported protocol: " + protocolType.name());
283+
}
284+
return true;
285+
}
286+
284287
@Override
285288
public boolean maintain(DataStore store) {
286289
return true;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ public CloudStackVolume getCloudStackVolume(Map<String, String> values) {
123123

124124
@Override
125125
public AccessGroup createAccessGroup(AccessGroup accessGroup) {
126-
s_logger.info("createAccessGroup : Creating Igroup with accessGroup request {} ", accessGroup);
126+
s_logger.info("createAccessGroup : Creating Igroup with access group request {} ", accessGroup);
127127
if (accessGroup == null || accessGroup.getIgroup() == null) {
128128
s_logger.error("createAccessGroup: Igroup creation failed. Invalid request: {}", accessGroup);
129-
throw new CloudRuntimeException("createAccessGroup : Failed to create Lun, invalid request");
129+
throw new CloudRuntimeException("createAccessGroup : Failed to create Igroup, invalid request");
130130
}
131131
try {
132132
// Get AuthHeader
@@ -176,7 +176,7 @@ public AccessGroup getAccessGroup(Map<String, String> values) {
176176
URI url = utils.generateURI(Constants.CREATE_IGROUP);
177177
url = utils.addQueryParamsToURI(url, values);
178178
s_logger.info("getAccessGroup: URL: {}", url);
179-
//TODO: It is possible that Lun creation will take time and we may need to handle through async job.
179+
180180
OntapResponse<Igroup> igroupResponse = sanFeignClient.getIgroupResponse(url, authHeader);
181181
if (igroupResponse == null || igroupResponse.getRecords() == null || igroupResponse.getRecords().size() == 0) {
182182
s_logger.error("getAccessGroup: Failed to fetch Igroup");
@@ -213,8 +213,8 @@ public void enableLogicalAccess(Map<String, String> values) {
213213
URI url = utils.generateURI(Constants.CREATE_LUNMAP);
214214
OntapResponse<LunMap> createdLunMap = sanFeignClient.createLunMap(url, authHeader, true, lunMapRequest);
215215
if (createdLunMap == null || createdLunMap.getRecords() == null || createdLunMap.getRecords().size() == 0) {
216-
s_logger.error("enableLogicalAccess: LunMap creation failed for Lun {} and igroup ", lunName, igroupName);
217-
throw new CloudRuntimeException("Failed to create LunMap: creation failed for Lun: " +lunName+ "and igroup: " + igroupName);
216+
s_logger.error("enableLogicalAccess: LunMap failed for Lun {} and igroup ", lunName, igroupName);
217+
throw new CloudRuntimeException("Failed to perform LunMap for Lun: " +lunName+ "and igroup: " + igroupName);
218218
}
219219
LunMap lunMap = createdLunMap.getRecords().get(0);
220220
s_logger.debug("enableLogicalAccess: LunMap created successfully. LunMap: {}", lunMap);

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class Constants {
4747

4848
public static final String PATH_SEPARATOR = "/";
4949
public static final String UNDERSCORE = "_";
50+
public static final String CS = "cs";
5051

5152
public static final String VOLUME_PATH_PREFIX = "/vol/";
5253

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/Utility.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,8 @@ public AccessGroup createAccessGroupRequestByProtocol(StoragePoolVO storagePool,
171171
String svmName = details.get(Constants.SVM_NAME);
172172
switch (protocol) {
173173
case ISCSI:
174-
String storagePoolName = storagePool.getName();
175-
//TODO: Check if we have to change the access group name format
176-
// Access group name format: StoragePoolName_ScopeId
177-
String igroupName = getIgroupName(storagePoolName, scopeId);
174+
// Access group name format: cs_svmName_scopeId
175+
String igroupName = getIgroupName(svmName, scopeId);
178176
Hypervisor.HypervisorType hypervisorType = storagePool.getHypervisor();
179177
return createSANAccessGroupRequest(svmName, igroupName, hypervisorType, hostsIdentifier);
180178
default:
@@ -193,7 +191,7 @@ public AccessGroup createSANAccessGroupRequest(String svmName, String igroupName
193191
igroup.setSvm(svm);
194192
}
195193

196-
if(igroupName == null || igroupName.isEmpty()) {
194+
if(igroupName != null || !igroupName.isEmpty()) {
197195
igroup.setName(igroupName);
198196
}
199197

@@ -211,7 +209,6 @@ public AccessGroup createSANAccessGroupRequest(String svmName, String igroupName
211209
}
212210
igroup.setInitiators(initiators);
213211
}
214-
215212
return accessGroupRequest;
216213
}
217214

@@ -220,8 +217,8 @@ public String getLunName(String volName, String lunName) {
220217
return Constants.VOLUME_PATH_PREFIX + volName + Constants.PATH_SEPARATOR + lunName;
221218
}
222219

223-
public String getIgroupName(String storagePoolName, long scopeId) {
220+
public String getIgroupName(String svmName, long scopeId) {
224221
// Igroup name format: StoragePoolName_ScopeId
225-
return storagePoolName + Constants.UNDERSCORE + scopeId;
222+
return Constants.CS + Constants.UNDERSCORE + svmName + Constants.UNDERSCORE + scopeId;
226223
}
227224
}

0 commit comments

Comments
 (0)