Updated Branches:
  refs/heads/javelin 60758785b -> b65f9ec41

add lifecycle and pool manager


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/b65f9ec4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/b65f9ec4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/b65f9ec4

Branch: refs/heads/javelin
Commit: b65f9ec414da84d51f23c69afae18419f80c1c84
Parents: 6075878
Author: Edison Su <[email protected]>
Authored: Mon Aug 27 18:15:41 2012 -0700
Committer: Edison Su <[email protected]>
Committed: Mon Aug 27 18:15:41 2012 -0700

----------------------------------------------------------------------
 .../DefaultPrimaryDataStoreLifeCycle.java          |  123 ++++++++++++++
 .../storage/manager/StoragePoolManagerImpl.java    |  129 +++++++++++++++
 .../storage/manager/StoragePoolService.java        |   39 +++++
 3 files changed, 291 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b65f9ec4/platform/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java
----------------------------------------------------------------------
diff --git 
a/platform/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java
 
b/platform/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java
new file mode 100644
index 0000000..0961220
--- /dev/null
+++ 
b/platform/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java
@@ -0,0 +1,123 @@
+package org.apache.cloudstack.storage.lifecycle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreDriver;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPoint;
+import 
org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPointSelector;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.CreateStoragePoolCommand;
+import com.cloud.agent.api.ModifyStoragePoolAnswer;
+import com.cloud.agent.api.ModifyStoragePoolCommand;
+import com.cloud.alert.AlertManager;
+import com.cloud.exception.StorageUnavailableException;
+import com.cloud.host.HostVO;
+import com.cloud.storage.StoragePoolHostVO;
+import com.cloud.storage.StoragePoolVO;
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.dao.StoragePoolDao;
+import com.cloud.storage.dao.StoragePoolHostDao;
+import com.cloud.utils.component.Inject;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class DefaultPrimaryDataStoreLifeCycle implements DataStoreLifeCycle {
+        private static final Logger s_logger = 
Logger.getLogger(DataStoreLifeCycle.class);
+       private DataStore _ds;
+       @Inject
+       StoragePoolDao _storagePoolDao;
+       @Inject
+       StoragePoolHostDao _poolHostDao;
+       public DefaultPrimaryDataStoreLifeCycle(DataStore ds) {
+               this._ds = ds;
+       }
+       
+
+       protected boolean createStoragePool(DataStoreEndPoint ep, StoragePoolVO 
pool) {
+               DataStoreDriver dsDriver = _ds.getDataStoreDriver();
+               CreateStoragePoolCommand cmd = new 
CreateStoragePoolCommand(true, pool);
+               final Answer answer = dsDriver.sendMessage(ep, cmd);
+               if (answer != null && answer.getResult()) {
+                       return true;
+               } else {
+                       throw new CloudRuntimeException(answer.getDetails());
+               }
+       }
+       
+        protected void connectHostToSharedPool(DataStoreEndPoint ep, 
StoragePoolVO pool) throws StorageUnavailableException {
+                DataStoreDriver dsDriver = _ds.getDataStoreDriver();
+                long hostId = ep.getHostId();
+                ModifyStoragePoolCommand cmd = new 
ModifyStoragePoolCommand(true, pool);
+                final Answer answer = dsDriver.sendMessage(ep, cmd);
+
+                if (answer == null) {
+                        throw new StorageUnavailableException("Unable to get 
an answer to the modify storage pool command", pool.getId());
+                }
+
+                if (!answer.getResult()) {
+                        throw new StorageUnavailableException("Unable 
establish connection from storage head to storage pool " + pool.getId() + " due 
to " + answer.getDetails(), pool.getId());
+                }
+
+                assert (answer instanceof ModifyStoragePoolAnswer) : "Well, 
now why won't you actually return the ModifyStoragePoolAnswer when it's 
ModifyStoragePoolCommand? Pool=" + pool.getId();
+                ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) 
answer;
+
+                StoragePoolHostVO poolHost = 
_poolHostDao.findByPoolHost(pool.getId(), hostId);
+                if (poolHost == null) {
+                        poolHost = new StoragePoolHostVO(pool.getId(), hostId, 
mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
+                        _poolHostDao.persist(poolHost);
+                } else {
+                        
poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", 
"/"));
+                }
+                
pool.setAvailableBytes(mspAnswer.getPoolInfo().getAvailableBytes());
+                
pool.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
+                _storagePoolDao.update(pool.getId(), pool);
+        }
+
+        public void add() {
+                DataStoreEndPointSelector dseps = _ds.getEndPointSelector();
+                List<DataStoreEndPoint> dsep = dseps.getEndPoints();
+                boolean success = false;
+                StoragePoolVO spool = _storagePoolDao.findById(_ds.getId());
+                for (DataStoreEndPoint ep : dsep) {
+                        success = createStoragePool(ep, spool);
+                        if (success) {
+                                break;
+                        }
+                }
+
+                List<DataStoreEndPoint> poolHosts = new 
ArrayList<DataStoreEndPoint>();
+                for (DataStoreEndPoint ep : dsep) {
+                        try {
+                                connectHostToSharedPool(ep, spool);
+                                poolHosts.add(ep);
+                        } catch (Exception e) {
+                                s_logger.debug("Failed to add storage on this 
ep: " + ep.getHostId());
+                        }
+                }
+       }
+
+       public void delete() {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void enable() {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void disable() {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void processEvent(DataStoreEvent event, Object... objs) {
+               // TODO Auto-generated method stub
+
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b65f9ec4/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolManagerImpl.java
 
b/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolManagerImpl.java
new file mode 100644
index 0000000..5fccf50
--- /dev/null
+++ 
b/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolManagerImpl.java
@@ -0,0 +1,129 @@
+/*
+ * 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.manager;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import 
org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
+
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.HostPodDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+import com.cloud.storage.StoragePoolStatus;
+import com.cloud.storage.StoragePoolVO;
+import com.cloud.storage.dao.StoragePoolDao;
+import com.cloud.utils.component.Adapters;
+import com.cloud.utils.component.Inject;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class StoragePoolManagerImpl implements StoragePoolService {
+       @Inject(adapter = StorageProvider.class)
+       protected Adapters<StorageProvider> _storageProviders;
+       @Inject
+       protected DataCenterDao _dcDao;
+       @Inject
+       protected HostPodDao _podDao;
+       @Inject
+       protected ClusterDao _clusterDao;
+       @Inject
+       protected StoragePoolDao _storagePoolDao;
+
+       public void deleteStoragePool(long poolId) {
+               StoragePool spool = _storagePoolDao.findById(poolId);
+               StorageProvider sp = 
findStorageProvider(spool.getStorageProvider());
+               DataStore ds = sp.getDataStore(spool);
+               DataStoreLifeCycle dslc = ds.getLifeCycle();
+               dslc.delete();
+       }
+
+       public void enableStoragePool(long poolId) {
+               // TODO Auto-generated method stub
+               
+       }
+
+       public void disableStoragePool(long poolId) {
+               // TODO Auto-generated method stub
+               
+       }
+
+       public Map<String, List<String>> getSupportedPrimaryStorages(long 
zoneId, HypervisorType hypervisor) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       public Map<String, List<String>> getSupportedSecondaryStorages(long 
zoneId) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+       
+       protected StorageProvider findStorageProvider(String name) {
+               Iterator<StorageProvider> spIter = _storageProviders.iterator();
+               StorageProvider sp = null;
+               while (spIter.hasNext()) {
+                       sp = spIter.next();
+                       if (sp.getProviderName().equalsIgnoreCase(name)) {
+                               break;
+                       }
+               }
+               
+               return sp;
+       }
+       
+       public StoragePool addStoragePool(long zoneId, long podId, long 
clusterId, long hostId, String URI, String storageType, String poolName, String 
storageProviderName, Map<String, String> params) {
+               StoragePoolVO spool = new StoragePoolVO();
+               long poolId = _storagePoolDao.getNextInSequence(Long.class, 
"id");
+        spool.setId(poolId);
+        spool.setDataCenterId(zoneId);
+        spool.setPodId(podId);
+        spool.setName(poolName);
+        spool.setClusterId(clusterId);
+        spool.setStorageProvider(storageProviderName);
+        spool.setStorageType(storageType);
+        spool.setStatus(StoragePoolStatus.Creating);
+        spool = _storagePoolDao.persist(spool);
+        
+        StorageProvider sp = findStorageProvider(storageProviderName);
+        DataStore ds = sp.addDataStore((StoragePool)spool, URI, params);
+        
+        DataStoreLifeCycle dslc = ds.getLifeCycle();
+        try {
+               dslc.add();
+        } catch (CloudRuntimeException e) {
+               _storagePoolDao.remove(spool.getId());
+               throw e;
+        }
+     
+        spool.setPath(ds.getURI());
+        spool.setUuid(ds.getUUID());
+        spool.setStatus(StoragePoolStatus.Up);
+        _storagePoolDao.update(spool.getId(), spool);
+        spool = _storagePoolDao.findById(spool.getId());
+        return spool;
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b65f9ec4/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolService.java
----------------------------------------------------------------------
diff --git 
a/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolService.java
 
b/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolService.java
new file mode 100644
index 0000000..ed21076
--- /dev/null
+++ 
b/platform/storage/src/org/apache/cloudstack/storage/manager/StoragePoolService.java
@@ -0,0 +1,39 @@
+/*
+ * 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.manager;
+
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public interface StoragePoolService {
+       StoragePool addStoragePool(long zoneId, long podId, long clusterId, 
long hostId, 
+                       String URI, 
+                       String storageType,
+                       String poolName,
+                       String storageProviderName,
+                       Map<String, String> params);
+       void deleteStoragePool(long poolId);
+       void enableStoragePool(long poolId);
+       void disableStoragePool(long poolId);
+       Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, 
HypervisorType hypervisor);
+       Map<String, List<String>> getSupportedSecondaryStorages(long zoneId);
+}

Reply via email to