-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Adding new Dell EMC ECS Object Storage Plugin for CloudStack #12124
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
Open
mhkadhum
wants to merge
6
commits into
apache:main
Choose a base branch
from
mhkadhum:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,188
−68
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f36ebf
Adding New Dell ECS Plugin to the API & editing Frontend for the ECS …
f131d41
Update AddObjectStorage.vue ECS Field Names and desc.
mhkadhum 625fb4e
Merge branch 'apache:main' into main
mhkadhum 124649f
add missing license
ce40daf
reverting update by pre-commit on tools/marvin/setup.py
mhkadhum 7dd1bf2
adding ECS Module in the Plugins pom.xml
mhkadhum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <artifactId>cloud-plugin-storage-object-ecs</artifactId> | ||
| <name>Apache CloudStack Plugin - ECS object storage provider</name> | ||
| <parent> | ||
| <groupId>org.apache.cloudstack</groupId> | ||
| <artifactId>cloudstack-plugins</artifactId> | ||
| <version>4.23.0.0-SNAPSHOT</version> | ||
| <relativePath>../../../pom.xml</relativePath> | ||
| </parent> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.cloudstack</groupId> | ||
| <artifactId>cloud-engine-storage</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.cloudstack</groupId> | ||
| <artifactId>cloud-engine-storage-object</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.cloudstack</groupId> | ||
| <artifactId>cloud-engine-schema</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
1,507 changes: 1,507 additions & 0 deletions
1,507
...rc/main/java/org/apache/cloudstack/storage/datastore/driver/EcsObjectStoreDriverImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
255 changes: 255 additions & 0 deletions
255
...n/java/org/apache/cloudstack/storage/datastore/lifecycle/EcsObjectStoreLifeCycleImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,255 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.cloudstack.storage.datastore.lifecycle; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.net.ssl.SSLContext; | ||
|
|
||
| import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; | ||
| import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO; | ||
| import org.apache.cloudstack.storage.object.datastore.ObjectStoreHelper; | ||
| import org.apache.cloudstack.storage.object.datastore.ObjectStoreProviderManager; | ||
| import org.apache.cloudstack.storage.object.store.lifecycle.ObjectStoreLifeCycle; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.apache.http.auth.UsernamePasswordCredentials; | ||
| import org.apache.http.client.methods.CloseableHttpResponse; | ||
| import org.apache.http.client.methods.HttpGet; // change to POST if ECS needs it | ||
| import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||
| import org.apache.http.impl.auth.BasicScheme; | ||
| import org.apache.http.impl.client.CloseableHttpClient; | ||
| import org.apache.http.impl.client.HttpClients; | ||
| import org.apache.http.ssl.SSLContextBuilder; | ||
| import org.apache.http.ssl.TrustStrategy; | ||
|
|
||
| import com.cloud.agent.api.StoragePoolInfo; | ||
| import com.cloud.hypervisor.Hypervisor.HypervisorType; | ||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
|
|
||
| public class EcsObjectStoreLifeCycleImpl implements ObjectStoreLifeCycle { | ||
|
|
||
| private static final Logger LOG = LogManager.getLogger(EcsObjectStoreLifeCycleImpl.class); | ||
|
|
||
| // detail keys coming from the API | ||
| private static final String MGMT_URL = "mgmt_url"; | ||
| private static final String SA_USER = "sa_user"; | ||
| private static final String SA_PASS = "sa_password"; | ||
| private static final String INSECURE = "insecure"; | ||
|
|
||
| // optional details (currently not used in persistence logic but accepted) | ||
| private static final String S3_HOST = "s3_host"; | ||
| private static final String NAMESPACE = "namespace"; | ||
|
|
||
| private static final String PROVIDER_NAME = "ECS"; | ||
|
|
||
| @Inject | ||
| ObjectStoreHelper objectStoreHelper; | ||
|
|
||
| @Inject | ||
| ObjectStoreProviderManager objectStoreMgr; | ||
|
|
||
| public EcsObjectStoreLifeCycleImpl() { | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Override | ||
| public DataStore initialize(Map<String, Object> dsInfos) { | ||
|
Contributor
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. this method can be split into several verify methods. Your code to maintain @mhkadhum , so I won’t -1 on this point but for readability it would be good. |
||
| if (objectStoreHelper == null) { | ||
| throw new CloudRuntimeException("ECS: ObjectStoreHelper is not injected"); | ||
| } | ||
| if (objectStoreMgr == null) { | ||
| throw new CloudRuntimeException("ECS: ObjectStoreProviderManager is not injected"); | ||
| } | ||
|
|
||
| // Top-level params (follow Ceph pattern) | ||
| String url = (String) dsInfos.get("url"); | ||
| String name = (String) dsInfos.get("name"); | ||
| Long size = (Long) dsInfos.get("size"); // may be null | ||
| String providerName = (String) dsInfos.get("providerName"); // should be "ECS" | ||
|
|
||
| Map<String, String> details = (Map<String, String>) dsInfos.get("details"); | ||
| if (details == null) { | ||
| throw new CloudRuntimeException("ECS: details map is missing"); | ||
| } | ||
|
|
||
| // Validate required details | ||
| String mgmtUrl = trim(details.get(MGMT_URL)); | ||
| String saUser = safe(details.get(SA_USER)); | ||
| String saPass = safe(details.get(SA_PASS)); | ||
| boolean insecure = Boolean.parseBoolean(details.getOrDefault(INSECURE, "false")); | ||
|
|
||
| if (mgmtUrl == null || mgmtUrl.isEmpty()) { | ||
| throw new CloudRuntimeException("ECS: missing required detail '" + MGMT_URL + "'"); | ||
| } | ||
| if (saUser.isEmpty()) { | ||
| throw new CloudRuntimeException("ECS: missing required detail '" + SA_USER + "'"); | ||
| } | ||
| if (saPass.isEmpty()) { | ||
| throw new CloudRuntimeException("ECS: missing required detail '" + SA_PASS + "'"); | ||
| } | ||
|
|
||
| if (providerName == null || providerName.isEmpty()) { | ||
| providerName = PROVIDER_NAME; | ||
| } | ||
|
|
||
| LOG.info("ECS initialize: provider='{}', name='{}', url='{}', mgmt_url='{}', insecure={}, s3_host='{}', namespace='{}'", | ||
| providerName, name, url, mgmtUrl, insecure, | ||
| details.get(S3_HOST), details.get(NAMESPACE)); | ||
|
|
||
| // Try ECS login up-front so we fail fast on bad config | ||
| loginAndGetToken(mgmtUrl, saUser, saPass, insecure); | ||
|
|
||
| // Put “canonical” values back into details (so DB keeps what we validated) | ||
| details.put(MGMT_URL, mgmtUrl); | ||
| details.put(SA_USER, saUser); | ||
| details.put(SA_PASS, saPass); | ||
| details.put(INSECURE, Boolean.toString(insecure)); | ||
|
|
||
| // Build objectStore parameters exactly like Ceph does | ||
| Map<String, Object> objectStoreParameters = new HashMap<>(); | ||
| objectStoreParameters.put("name", name); | ||
| objectStoreParameters.put("url", url); | ||
| objectStoreParameters.put("size", size); | ||
| objectStoreParameters.put("providerName", providerName); | ||
|
|
||
| try { | ||
| LOG.info("ECS: creating ObjectStore in DB: name='{}', provider='{}', url='{}'", | ||
| name, providerName, url); | ||
| ObjectStoreVO objectStore = objectStoreHelper.createObjectStore(objectStoreParameters, details); | ||
| if (objectStore == null) { | ||
| throw new CloudRuntimeException("ECS: createObjectStore returned null"); | ||
| } | ||
|
|
||
| DataStore store = objectStoreMgr.getObjectStore(objectStore.getId()); | ||
| if (store == null) { | ||
| throw new CloudRuntimeException("ECS: getObjectStore returned null for id=" + objectStore.getId()); | ||
| } | ||
|
|
||
| LOG.info("ECS: object store created: id={}, name='{}'", objectStore.getId(), name); | ||
| return store; | ||
| } catch (RuntimeException e) { | ||
| String msg = "ECS: failed to persist object store '" + name + "': " + safeMsg(e); | ||
| LOG.error(msg, e); | ||
| throw new CloudRuntimeException(msg, e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean attachCluster(DataStore store, ClusterScope scope) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean maintain(DataStore store) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean cancelMaintain(DataStore store) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean deleteDataStore(DataStore store) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean migrateToObjectStore(DataStore store) { | ||
| return false; | ||
| } | ||
|
|
||
| // ---------- helpers ---------- | ||
|
|
||
| private static String safe(String v) { | ||
| return v == null ? "" : v.trim(); | ||
| } | ||
|
|
||
| private static String trim(String v) { | ||
| if (v == null) { | ||
| return null; | ||
| } | ||
| v = v.trim(); | ||
| return v.endsWith("/") ? v.substring(0, v.length() - 1) : v; | ||
| } | ||
|
|
||
| private static String safeMsg(Throwable t) { | ||
| if (t == null) { | ||
| return "unknown"; | ||
| } | ||
| String m = t.getMessage(); | ||
| return (m == null || m.isEmpty()) ? t.getClass().getSimpleName() : m; | ||
| } | ||
|
|
||
| private CloseableHttpClient buildHttpClient(boolean insecure) { | ||
| if (!insecure) { | ||
| return HttpClients.createDefault(); | ||
| } | ||
| try { | ||
| TrustStrategy trustAll = (chain, authType) -> true; | ||
| SSLContext sslContext = SSLContextBuilder.create() | ||
| .loadTrustMaterial(null, trustAll) | ||
| .build(); | ||
| return HttpClients.custom() | ||
| .setSSLContext(sslContext) | ||
| .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) | ||
| .build(); | ||
| } catch (Exception e) { | ||
| throw new CloudRuntimeException("ECS: failed to build HttpClient", e); | ||
| } | ||
| } | ||
|
|
||
| private String loginAndGetToken(String mgmtUrl, String user, String pass, boolean insecure) { | ||
| try (CloseableHttpClient http = buildHttpClient(insecure)) { | ||
| HttpGet get = new HttpGet(mgmtUrl + "/login"); | ||
| get.addHeader(new BasicScheme().authenticate( | ||
| new UsernamePasswordCredentials(user, pass), get, null)); | ||
| try (CloseableHttpResponse resp = http.execute(get)) { | ||
| int status = resp.getStatusLine().getStatusCode(); | ||
| if (status != 200 && status != 201) { | ||
| throw new CloudRuntimeException("ECS /login failed: HTTP " + status); | ||
| } | ||
| if (resp.getFirstHeader("X-SDS-AUTH-TOKEN") == null) { | ||
| throw new CloudRuntimeException("ECS /login missing X-SDS-AUTH-TOKEN"); | ||
| } | ||
| return resp.getFirstHeader("X-SDS-AUTH-TOKEN").getValue(); | ||
| } | ||
| } catch (Exception e) { | ||
| String msg = "ECS: management login error: " + safeMsg(e); | ||
| LOG.error(msg, e); | ||
| throw new CloudRuntimeException(msg, e); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
methods
createBucket, listBuckets,listBucketObjects,deleteBucket,setBucketPolicy,getBucketPolicy,setOrSuspendVersioning,setBucketQuota,ensureAccountUserAndSecretandecsBucketExists` are rather great. Again not my code to maintain, but extracting smaller methods will make it more readible and may help find some code deduplication possibilities.