You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/07/13 10:52:20 UTC
[4/4] git commit: updated refs/heads/4.2 to 7e6c1a0
add inital swift support
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c888fc6b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c888fc6b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c888fc6b
Branch: refs/heads/4.2
Commit: c888fc6b75d3ad222867dd69b9f1d0cb9b6b9867
Parents: 7ec12da
Author: Edison Su <su...@gmail.com>
Authored: Fri Jul 12 18:01:39 2013 -0700
Committer: Edison Su <ed...@citrix.com>
Committed: Sat Jul 13 01:52:03 2013 -0700
----------------------------------------------------------------------
api/src/com/cloud/agent/api/to/SwiftTO.java | 8 +-
api/src/com/cloud/resource/ResourceService.java | 15 -
.../api/command/admin/swift/AddSwiftCmd.java | 118 -
.../api/command/admin/swift/ListSwiftsCmd.java | 70 -
.../command/DownloadSystemTemplateCommand.java | 129 --
.../schema/src/com/cloud/storage/SwiftVO.java | 2 +-
.../src/com/cloud/storage/dao/SwiftDao.java | 31 -
.../src/com/cloud/storage/dao/SwiftDaoImpl.java | 58 -
engine/storage/image/pom.xml | 1 +
.../MockLocalNfsSecondaryStorageResource.java | 57 +-
.../storage/image/BaseImageStoreDriverImpl.java | 30 +-
.../driver/SwiftImageStoreDriverImpl.java | 47 +-
scripts/storage/secondary/swift | 2010 +++++++-----------
.../com/cloud/capacity/CapacityManagerImpl.java | 3 -
.../configuration/ConfigurationManagerImpl.java | 31 -
.../com/cloud/resource/ResourceManagerImpl.java | 33 -
.../com/cloud/server/ManagementServerImpl.java | 7 -
.../storage/snapshot/SnapshotManagerImpl.java | 3 -
.../com/cloud/storage/swift/SwiftManager.java | 57 -
.../cloud/storage/swift/SwiftManagerImpl.java | 298 ---
.../template/HypervisorTemplateAdapter.java | 3 +-
.../cloud/resource/MockResourceManagerImpl.java | 39 -
.../networkoffering/ChildTestConfiguration.java | 14 -
services/secondary-storage/pom.xml | 1 +
.../LocalNfsSecondaryStorageResource.java | 62 +-
.../resource/NfsSecondaryStorageResource.java | 11 +-
26 files changed, 891 insertions(+), 2247 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/api/src/com/cloud/agent/api/to/SwiftTO.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/to/SwiftTO.java b/api/src/com/cloud/agent/api/to/SwiftTO.java
index e1697f9..5d74003 100644
--- a/api/src/com/cloud/agent/api/to/SwiftTO.java
+++ b/api/src/com/cloud/agent/api/to/SwiftTO.java
@@ -25,15 +25,18 @@ public class SwiftTO implements DataStoreTO {
String userName;
String key;
+ String container;
public SwiftTO() { }
- public SwiftTO(Long id, String url, String account, String userName, String key) {
+ public SwiftTO(Long id, String url, String account, String userName, String key,
+ String container) {
this.id = id;
this.url = url;
this.account = account;
this.userName = userName;
this.key = key;
+ this.container = container;
}
public Long getId() {
@@ -61,6 +64,9 @@ public class SwiftTO implements DataStoreTO {
return DataStoreRole.Image;
}
+ public String getContainer() {
+ return this.container;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/api/src/com/cloud/resource/ResourceService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/resource/ResourceService.java b/api/src/com/cloud/resource/ResourceService.java
index ce0df63..25298cc 100755
--- a/api/src/com/cloud/resource/ResourceService.java
+++ b/api/src/com/cloud/resource/ResourceService.java
@@ -27,10 +27,6 @@ import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd;
import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
-import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd;
-import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd;
-import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd;
-import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd;
import com.cloud.exception.DiscoveryException;
import com.cloud.exception.InvalidParameterValueException;
@@ -38,9 +34,6 @@ import com.cloud.exception.ResourceInUseException;
import com.cloud.host.Host;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.org.Cluster;
-import com.cloud.storage.S3;
-import com.cloud.storage.Swift;
-import com.cloud.utils.Pair;
import com.cloud.utils.fsm.NoTransitionException;
public interface ResourceService {
@@ -97,16 +90,8 @@ public interface ResourceService {
Cluster getCluster(Long clusterId);
- Swift discoverSwift(AddSwiftCmd addSwiftCmd) throws DiscoveryException;
-
- S3 discoverS3(AddS3Cmd cmd) throws DiscoveryException;
-
List<HypervisorType> getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId);
- Pair<List<? extends Swift>, Integer> listSwifts(ListSwiftsCmd cmd);
-
- List<? extends S3> listS3s(ListS3sCmd cmd);
-
boolean releaseHostReservation(Long hostId);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java b/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java
deleted file mode 100644
index 462b529..0000000
--- a/api/src/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java
+++ /dev/null
@@ -1,118 +0,0 @@
-// 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.api.command.admin.swift;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
-import org.apache.cloudstack.api.response.ImageStoreResponse;
-import org.apache.log4j.Logger;
-
-import com.cloud.exception.DiscoveryException;
-import com.cloud.storage.ImageStore;
-import com.cloud.user.Account;
-
-@APICommand(name = "addSwift", description = "Adds Swift.", responseObject = ImageStoreResponse.class, since="3.0.0")
-public class AddSwiftCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(AddSwiftCmd.class.getName());
- private static final String s_name = "addswiftresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, description = "the URL for swift")
- private String url;
-
- @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account for swift")
- private String account;
-
- @Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, description = "the username for swift")
- private String username;
-
- @Parameter(name = ApiConstants.KEY, type = CommandType.STRING, description = " key for the user for swift")
- private String key;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getUrl() {
- return url;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- public String getAccount() {
- return account;
- }
-
- public String getUsername() {
- return username;
- }
-
- public String getKey() {
- return key;
- }
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public void execute(){
- AddImageStoreCmd cmd = new AddImageStoreCmd();
- cmd.setProviderName("Swift");
- cmd.setUrl(this.getUrl());
- Map<String, String> details = new HashMap<String, String>();
- details.put(ApiConstants.ACCOUNT, this.getAccount());
- details.put(ApiConstants.USERNAME, this.getUsername());
- details.put(ApiConstants.KEY, this.getKey());
-
-
- try{
- ImageStore result = _storageService.discoverImageStore(cmd);
- ImageStoreResponse storeResponse = null;
- if (result != null ) {
- storeResponse = _responseGenerator.createImageStoreResponse(result);
- storeResponse.setResponseName(getCommandName());
- storeResponse.setObjectName("secondarystorage");
- this.setResponseObject(storeResponse);
- } else {
- throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
- }
- } catch (DiscoveryException ex) {
- s_logger.warn("Exception: ", ex);
- throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java
deleted file mode 100644
index b0408f4..0000000
--- a/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java
+++ /dev/null
@@ -1,70 +0,0 @@
-// 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.api.command.admin.swift;
-
-import org.apache.cloudstack.api.APICommand;
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseListCmd;
-import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd;
-import org.apache.cloudstack.api.response.ImageStoreResponse;
-import org.apache.cloudstack.api.response.ListResponse;
-import org.apache.log4j.Logger;
-
-import com.cloud.user.Account;
-
-@APICommand(name = "listSwifts", description = "List Swift.", responseObject = ImageStoreResponse.class, since="3.0.0")
-public class ListSwiftsCmd extends BaseListCmd {
- public static final Logger s_logger = Logger.getLogger(ListSwiftsCmd.class.getName());
- private static final String s_name = "listswiftsresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "the id of the swift")
- private Long id;
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- public Long getId() {
- return id;
- }
-
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public void execute(){
-
- ListImageStoresCmd cmd = new ListImageStoresCmd();
- cmd.setProvider("Swift");
- ListResponse<ImageStoreResponse> response = _queryService.searchForImageStores(cmd);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/engine/api/src/org/apache/cloudstack/storage/command/DownloadSystemTemplateCommand.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/command/DownloadSystemTemplateCommand.java b/engine/api/src/org/apache/cloudstack/storage/command/DownloadSystemTemplateCommand.java
deleted file mode 100644
index 9528ff7..0000000
--- a/engine/api/src/org/apache/cloudstack/storage/command/DownloadSystemTemplateCommand.java
+++ /dev/null
@@ -1,129 +0,0 @@
-// 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.command;
-
-import com.cloud.agent.api.Command;
-import com.cloud.agent.api.storage.PasswordAuth;
-import com.cloud.agent.api.storage.Proxy;
-import com.cloud.agent.api.to.DataStoreTO;
-import com.cloud.template.VirtualMachineTemplate;
-
-public class DownloadSystemTemplateCommand extends Command {
-
- private PasswordAuth auth;
- private Proxy _proxy;
- private DataStoreTO _store;
- private Long resourceId;
- private Long accountId;
- private String url;
- private Long maxDownloadSizeInBytes;
- private String name;
-
- protected DownloadSystemTemplateCommand() {
- super();
- }
-
- public DownloadSystemTemplateCommand(DataStoreTO store, String secUrl, VirtualMachineTemplate template,
- Long maxDownloadSizeInBytes) {
- super();
- this._store = store;
- this.accountId = template.getAccountId();
- this.url = secUrl;
- this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
- this.resourceId = template.getId();
- this.name = template.getUniqueName();
- }
-
- public DownloadSystemTemplateCommand(DataStoreTO store, String secUrl, String url, VirtualMachineTemplate template,
- String user, String passwd, Long maxDownloadSizeInBytes) {
- super();
- this._store = store;
- this.accountId = template.getAccountId();
- this.url = secUrl;
- this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
- this.resourceId = template.getId();
- auth = new PasswordAuth(user, passwd);
- this.name = template.getUniqueName();
- }
-
- public PasswordAuth getAuth() {
- return auth;
- }
-
- public void setCreds(String userName, String passwd) {
- auth = new PasswordAuth(userName, passwd);
- }
-
- public Proxy getProxy() {
- return _proxy;
- }
-
- public void setProxy(Proxy proxy) {
- _proxy = proxy;
- }
-
- public Long getMaxDownloadSizeInBytes() {
- return maxDownloadSizeInBytes;
- }
-
- public DataStoreTO getDataStore() {
- return _store;
- }
-
- public void setDataStore(DataStoreTO _store) {
- this._store = _store;
- }
-
- public Long getResourceId() {
- return resourceId;
- }
-
- public void setResourceId(Long resourceId) {
- this.resourceId = resourceId;
- }
-
- public Long getAccountId() {
- return accountId;
- }
-
- public void setAccountId(Long accountId) {
- this.accountId = accountId;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public boolean executeInSequence() {
- // TODO Auto-generated method stub
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/engine/schema/src/com/cloud/storage/SwiftVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/SwiftVO.java b/engine/schema/src/com/cloud/storage/SwiftVO.java
index 4136a22..1389242 100644
--- a/engine/schema/src/com/cloud/storage/SwiftVO.java
+++ b/engine/schema/src/com/cloud/storage/SwiftVO.java
@@ -99,7 +99,7 @@ public class SwiftVO implements Swift, InternalIdentity {
@Override
public SwiftTO toSwiftTO() {
- return new SwiftTO(getId(), getUrl(), getAccount(), getUserName(), getKey());
+ return null;
}
@Override
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/engine/schema/src/com/cloud/storage/dao/SwiftDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/SwiftDao.java b/engine/schema/src/com/cloud/storage/dao/SwiftDao.java
deleted file mode 100644
index 72c5219..0000000
--- a/engine/schema/src/com/cloud/storage/dao/SwiftDao.java
+++ /dev/null
@@ -1,31 +0,0 @@
-// 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 com.cloud.storage.dao;
-
-import com.cloud.agent.api.to.SwiftTO;
-import com.cloud.storage.SwiftVO;
-import com.cloud.utils.db.GenericDao;
-
-/**
- *
- *
- */
-
-public interface SwiftDao extends GenericDao<SwiftVO, Long> {
-
- SwiftTO getSwiftTO(Long swiftId);
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/engine/schema/src/com/cloud/storage/dao/SwiftDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/SwiftDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/SwiftDaoImpl.java
deleted file mode 100644
index 0714690..0000000
--- a/engine/schema/src/com/cloud/storage/dao/SwiftDaoImpl.java
+++ /dev/null
@@ -1,58 +0,0 @@
-// 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 com.cloud.storage.dao;
-
-import java.util.Collections;
-import java.util.List;
-
-import javax.ejb.Local;
-
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.agent.api.to.SwiftTO;
-import com.cloud.storage.SwiftVO;
-import com.cloud.utils.db.GenericDaoBase;
-
-/**
- *
- *
- */
-@Component
-@Local(value = { SwiftDao.class })
-public class SwiftDaoImpl extends GenericDaoBase<SwiftVO, Long> implements SwiftDao {
- public static final Logger s_logger = Logger.getLogger(SwiftDaoImpl.class.getName());
-
- @Override
- public SwiftTO getSwiftTO(Long swiftId) {
- if (swiftId != null) {
- SwiftVO swift = findById(swiftId);
- if (swift != null) {
- return swift.toSwiftTO();
- }
- return null;
- }
-
- List<SwiftVO> swiftVOs = listAll();
- if (swiftVOs == null || swiftVOs.size() < 1) {
- return null;
- } else {
- Collections.shuffle(swiftVOs);
- return swiftVOs.get(0).toSwiftTO();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/engine/storage/image/pom.xml
----------------------------------------------------------------------
diff --git a/engine/storage/image/pom.xml b/engine/storage/image/pom.xml
index c4cf14c..c4d2d1b 100644
--- a/engine/storage/image/pom.xml
+++ b/engine/storage/image/pom.xml
@@ -36,6 +36,7 @@
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
+
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java
index 4d93296..75239c6 100644
--- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java
+++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/MockLocalNfsSecondaryStorageResource.java
@@ -27,7 +27,6 @@ import java.util.List;
import javax.naming.ConfigurationException;
-import org.apache.cloudstack.storage.command.DownloadSystemTemplateCommand;
import org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource;
import org.apache.cloudstack.storage.template.DownloadManagerImpl;
import org.springframework.stereotype.Component;
@@ -75,61 +74,9 @@ public class MockLocalNfsSecondaryStorageResource extends NfsSecondaryStorageRes
@Override
public Answer executeRequest(Command cmd) {
- if (cmd instanceof DownloadSystemTemplateCommand) {
- return execute((DownloadSystemTemplateCommand) cmd);
- } else {
- // return Answer.createUnsupportedCommandAnswer(cmd);
- return super.executeRequest(cmd);
- }
+ // return Answer.createUnsupportedCommandAnswer(cmd);
+ return super.executeRequest(cmd);
}
- private Answer execute(DownloadSystemTemplateCommand cmd) {
- DataStoreTO dstore = cmd.getDataStore();
- if (dstore instanceof S3TO) {
- // TODO: how to handle download progress for S3
- S3TO s3 = (S3TO) cmd.getDataStore();
- String url = cmd.getUrl();
- String user = null;
- String password = null;
- if (cmd.getAuth() != null) {
- user = cmd.getAuth().getUserName();
- password = new String(cmd.getAuth().getPassword());
- }
- // get input stream from the given url
- InputStream in = UriUtils.getInputStreamFromUrl(url, user, password);
- URL urlObj;
- try {
- urlObj = new URL(url);
- } catch (MalformedURLException e) {
- throw new CloudRuntimeException("URL is incorrect: " + url);
- }
- final String bucket = s3.getBucketName();
- // convention is no / in the end for install path based on S3Utils
- // implementation.
- String path = determineS3TemplateDirectory(cmd.getAccountId(), cmd.getResourceId(), cmd.getName());
- // template key is
- // TEMPLATE_ROOT_DIR/account_id/template_id/template_name
- String key = join(asList(path, urlObj.getFile()), S3Utils.SEPARATOR);
- S3Utils.putObject(s3, in, bucket, key);
- List<S3ObjectSummary> s3Obj = S3Utils.getDirectory(s3, bucket, path);
- if (s3Obj == null || s3Obj.size() == 0) {
- return new Answer(cmd, false, "Failed to download to S3 bucket: " + bucket + " with key: " + key);
- } else {
- return new DownloadAnswer(null, 100, null, Status.DOWNLOADED, path, path, s3Obj.get(0).getSize(), s3Obj
- .get(0).getSize(), s3Obj.get(0).getETag());
- }
- } else if (dstore instanceof NfsTO) {
- return new Answer(cmd, false, "Nfs needs to be pre-installed with system vm templates");
- } else if (dstore instanceof SwiftTO) {
- // TODO: need to move code from
- // execute(uploadTemplateToSwiftFromSecondaryStorageCommand) here,
- // but we need to handle
- // source is url, most likely we need to modify our existing
- // swiftUpload python script.
- return new Answer(cmd, false, "Swift is not currently support DownloadCommand");
- } else {
- return new Answer(cmd, false, "Unsupported image data store: " + dstore);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
index 8646247..f77226d 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
@@ -20,8 +20,10 @@ package org.apache.cloudstack.storage.image;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.storage.DownloadAnswer;
+import com.cloud.agent.api.storage.Proxy;
import com.cloud.agent.api.to.DataObjectType;
import com.cloud.agent.api.to.DataTO;
+import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VolumeVO;
@@ -46,12 +48,14 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
import org.apache.log4j.Logger;
import javax.inject.Inject;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Date;
public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver {
private static final Logger s_logger = Logger.getLogger(BaseImageStoreDriverImpl.class);
@Inject
- VMTemplateDao _templateDao;
+ protected VMTemplateDao _templateDao;
@Inject
DownloadMonitor _downloadMonitor;
@Inject
@@ -62,6 +66,22 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver {
TemplateDataStoreDao _templateStoreDao;
@Inject
EndPointSelector _epSelector;
+ @Inject
+ ConfigurationDao configDao;
+ protected String _proxy = null;
+
+ protected Proxy getHttpProxy() {
+ if (_proxy == null) {
+ return null;
+ }
+ try {
+ URI uri = new URI(_proxy);
+ Proxy prx = new Proxy(uri);
+ return prx;
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
@Override
public DataTO getTO(DataObject data) {
@@ -77,6 +97,14 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver {
}
}
+ protected Long getMaxTemplateSizeInBytes() {
+ try {
+ return Long.parseLong(configDao.getValue("max.template.iso.size")) * 1024L * 1024L * 1024L;
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
@Override
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c888fc6b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
index d6d6cd2..d971850 100644
--- a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
+++ b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
@@ -19,13 +19,26 @@
package org.apache.cloudstack.storage.datastore.driver;
import java.util.Map;
+import java.util.Timer;
import javax.inject.Inject;
+import com.cloud.agent.api.storage.DownloadAnswer;
+import com.cloud.agent.api.to.DataObjectType;
+import com.cloud.storage.download.DownloadListener;
+import com.cloud.storage.template.TemplateConstants;
+import com.cloud.storage.upload.UploadListener;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.utils.component.ComponentContext;
import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.*;
+import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
+import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
+import org.apache.cloudstack.storage.command.DownloadCommand;
+import org.apache.cloudstack.storage.command.DownloadProgressCommand;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
import org.apache.cloudstack.storage.image.BaseImageStoreDriverImpl;
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
+import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.log4j.Logger;
import com.cloud.agent.api.to.DataStoreTO;
@@ -38,13 +51,15 @@ public class SwiftImageStoreDriverImpl extends BaseImageStoreDriverImpl {
@Inject
ImageStoreDetailsDao _imageStoreDetailsDao;
+ @Inject
+ EndPointSelector _epSelector;
@Override
public DataStoreTO getStoreTO(DataStore store) {
ImageStoreImpl imgStore = (ImageStoreImpl) store;
Map<String, String> details = _imageStoreDetailsDao.getDetails(imgStore.getId());
return new SwiftTO(imgStore.getId(), imgStore.getUri(), details.get(ApiConstants.ACCOUNT),
- details.get(ApiConstants.USERNAME), details.get(ApiConstants.KEY));
+ details.get(ApiConstants.USERNAME), details.get(ApiConstants.KEY), details.get(ApiConstants.S3_BUCKET_NAME));
}
@Override
@@ -52,4 +67,32 @@ public class SwiftImageStoreDriverImpl extends BaseImageStoreDriverImpl {
throw new UnsupportedServiceException("Extract entity url is not yet supported for Swift image store provider");
}
+ @Override
+ public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
+ Long maxTemplateSizeInBytes = getMaxTemplateSizeInBytes();
+ VirtualMachineTemplate tmpl = _templateDao.findById(data.getId());
+ DownloadCommand dcmd = new DownloadCommand((TemplateObjectTO)(data.getTO()), maxTemplateSizeInBytes);
+ dcmd.setProxy(getHttpProxy());
+
+ EndPoint ep = _epSelector.select(data);
+ if (ep == null) {
+ s_logger.warn("There is no secondary storage VM for downloading template to image store " + dataStore.getName());
+ return;
+ }
+
+ CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
+ AsyncCallbackDispatcher<SwiftImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher
+ .create(this);
+ caller.setContext(context);
+
+ if (data.getType() == DataObjectType.TEMPLATE) {
+ caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
+ } else if (data.getType() == DataObjectType.VOLUME) {
+ caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
+ }
+ ep.sendMessageAsync(dcmd, caller);
+
+
+ }
+
}