Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
CSTACKEX-35 Create Async#14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -20,33 +20,111 @@ | ||
| package org.apache.cloudstack.storage.utils; | ||
| import com.cloud.utils.StringUtils; | ||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; | ||
| import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; | ||
| import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; | ||
| import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; | ||
| import org.apache.cloudstack.storage.feign.model.Lun; | ||
| import org.apache.cloudstack.storage.feign.model.LunSpace; | ||
| import org.apache.cloudstack.storage.feign.model.OntapStorage; | ||
| import org.apache.cloudstack.storage.feign.model.Svm; | ||
| import org.apache.cloudstack.storage.provider.StorageProviderFactory; | ||
| import org.apache.cloudstack.storage.service.StorageStrategy; | ||
| import org.apache.cloudstack.storage.service.model.CloudStackVolume; | ||
| import org.apache.cloudstack.storage.service.model.ProtocolType; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.util.Base64Utils; | ||
| import javax.inject.Inject; | ||
| import java.net.URI; | ||
| import java.util.Map; | ||
| @Component | ||
| public class Utility { | ||
| @Inject | ||
| OntapStorage ontapStorage; | ||
| private static final Logger s_logger = LogManager.getLogger(Utility.class); | ||
| @Inject private OntapStorage ontapStorage; | ||
| @Inject private PrimaryDataStoreDao storagePoolDao; | ||
| @Inject private StoragePoolDetailsDao storagePoolDetailsDao; | ||
| private static final String BASIC = "Basic"; | ||
| private static final String AUTH_HEADER_COLON = ":"; | ||
| /** | ||
| * Method generates authentication headers using storage backend credentials passed as normal string | ||
| * @param username -->> username of the storage backend | ||
| * @param password -->> normal decoded password of the storage backend | ||
| * | ||
| * @param username -->> username of the storage backend | ||
| * @param password -->> normal decoded password of the storage backend | ||
| * @return | ||
| */ | ||
| public String generateAuthHeader(String username, String password) { | ||
| public String generateAuthHeader(String username, String password) { | ||
| byte[] encodedBytes = Base64Utils.encode((username + AUTH_HEADER_COLON + password).getBytes()); | ||
| return BASIC + StringUtils.SPACE + new String(encodedBytes); | ||
| } | ||
| public URI generateURI(String path) { | ||
| public URI generateURI(String path) { | ||
| String uriString = Constants.HTTPS + ontapStorage.getManagementLIF() + path; | ||
| return URI.create(uriString); | ||
| } | ||
| public CloudStackVolume createCloudStackVolumeRequestByProtocol(StoragePoolVO storagePool, Map<String, String> details, DataObject dataObject) { | ||
| CloudStackVolume cloudStackVolumeRequest = null; | ||
| String protocol = details.get(Constants.PROTOCOL); | ||
| if (ProtocolType.ISCSI.name().equalsIgnoreCase(protocol)) { | ||
| cloudStackVolumeRequest = new CloudStackVolume(); | ||
| Lun lunRequest = new Lun(); | ||
| Svm svm = new Svm(); | ||
| svm.setName(details.get(Constants.SVM_NAME)); | ||
| lunRequest.setSvm(svm); | ||
| LunSpace lunSpace = new LunSpace(); | ||
| lunSpace.setSize(dataObject.getSize()); | ||
| lunRequest.setSpace(lunSpace); | ||
| //Lun name is full path like in unified "/vol/VolumeName/LunName" | ||
| String lunFullName = Constants.VOLUME_PATH_PREFIX + storagePool.getName() + Constants.PATH_SEPARATOR + dataObject.getName(); | ||
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add example for lun full name Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! | ||
| lunRequest.setName(lunFullName); | ||
| String hypervisorType = storagePool.getHypervisor().name(); | ||
| String osType = null; | ||
| switch (hypervisorType) { | ||
| case Constants.KVM: | ||
| osType = Lun.OsTypeEnum.LINUX.getValue(); | ||
| break; | ||
| default: | ||
| String errMsg = "createCloudStackVolume : Unsupported hypervisor type " + hypervisorType + " for ONTAP storage"; | ||
| s_logger.error(errMsg); | ||
| throw new CloudRuntimeException(errMsg); | ||
| } | ||
| lunRequest.setOsType(Lun.OsTypeEnum.valueOf(osType)); | ||
| cloudStackVolumeRequest.setLun(lunRequest); | ||
| return cloudStackVolumeRequest; | ||
| } else { | ||
| throw new CloudRuntimeException("createCloudStackVolumeRequestByProtocol: Unsupported protocol " + protocol); | ||
| } | ||
| } | ||
| public StorageStrategy getStrategyByStoragePoolDetails(Map<String, String> details) { | ||
| if (details == null || details.isEmpty()) { | ||
| s_logger.error("getStrategyByStoragePoolDetails: Storage pool details are null or empty"); | ||
| throw new CloudRuntimeException("getStrategyByStoragePoolDetails: Storage pool details are null or empty"); | ||
| } | ||
| String protocol = details.get(Constants.PROTOCOL); | ||
| OntapStorage ontapStorage = new OntapStorage(details.get(Constants.USERNAME), details.get(Constants.PASSWORD), | ||
| details.get(Constants.MANAGEMENT_LIF), details.get(Constants.SVM_NAME), ProtocolType.valueOf(protocol), | ||
| Boolean.parseBoolean(details.get(Constants.IS_DISAGGREGATED))); | ||
| StorageStrategy storageStrategy = StorageProviderFactory.getStrategy(ontapStorage); | ||
| boolean isValid = storageStrategy.connect(); | ||
| if (isValid) { | ||
| s_logger.info("Connection to Ontap SVM [{}] successful", details.get(Constants.SVM_NAME)); | ||
| return storageStrategy; | ||
| } else { | ||
| s_logger.error("getStrategyByStoragePoolDetails: Connection to Ontap SVM [" + details.get(Constants.SVM_NAME) + "] failed"); | ||
| throw new CloudRuntimeException("getStrategyByStoragePoolDetails: Connection to Ontap SVM [" + details.get(Constants.SVM_NAME) + "] failed"); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add TODO, based on testing need to covert this createLun to Async
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!