diff --git a/agent/src/com/cloud/agent/AgentShell.java b/agent/src/com/cloud/agent/AgentShell.java index cf454b8c89c..e7f114bc412 100644 --- a/agent/src/com/cloud/agent/AgentShell.java +++ b/agent/src/com/cloud/agent/AgentShell.java @@ -82,6 +82,7 @@ public class AgentShell implements IAgentShell, Daemon { private int _pingRetries; private final List _agents = new ArrayList(); + public AgentShell() { } diff --git a/api/src/com/cloud/storage/StoragePool.java b/api/src/com/cloud/storage/StoragePool.java index 8b95383c537..8f8b8644ddc 100644 --- a/api/src/com/cloud/storage/StoragePool.java +++ b/api/src/com/cloud/storage/StoragePool.java @@ -58,7 +58,7 @@ public interface StoragePool extends Identity, InternalIdentity { /** * @return available storage in bytes */ - long getAvailableBytes(); + long getUsedBytes(); Long getClusterId(); diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in index 8d251eed66f..181219a611f 100644 --- a/client/tomcatconf/applicationContext.xml.in +++ b/client/tomcatconf/applicationContext.xml.in @@ -815,6 +815,7 @@ + diff --git a/client/tomcatconf/log4j-cloud.xml.in b/client/tomcatconf/log4j-cloud.xml.in index 0e7f004eb80..fc1c29ef5e1 100755 --- a/client/tomcatconf/log4j-cloud.xml.in +++ b/client/tomcatconf/log4j-cloud.xml.in @@ -132,6 +132,10 @@ under the License. + + + + diff --git a/core/test/org/apache/cloudstack/api/agent/test/BackupSnapshotCommandTest.java b/core/test/org/apache/cloudstack/api/agent/test/BackupSnapshotCommandTest.java index 40083a8e1bc..989059322a9 100644 --- a/core/test/org/apache/cloudstack/api/agent/test/BackupSnapshotCommandTest.java +++ b/core/test/org/apache/cloudstack/api/agent/test/BackupSnapshotCommandTest.java @@ -83,7 +83,7 @@ public class BackupSnapshotCommandTest { }; @Override - public long getAvailableBytes() { + public long getUsedBytes() { return 0L; }; diff --git a/core/test/org/apache/cloudstack/api/agent/test/CheckNetworkAnswerTest.java b/core/test/org/apache/cloudstack/api/agent/test/CheckNetworkAnswerTest.java index 1853d3967c9..4db65570f1b 100644 --- a/core/test/org/apache/cloudstack/api/agent/test/CheckNetworkAnswerTest.java +++ b/core/test/org/apache/cloudstack/api/agent/test/CheckNetworkAnswerTest.java @@ -16,9 +16,15 @@ // under the License. package org.apache.cloudstack.api.agent.test; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import com.cloud.agent.api.storage.ResizeVolumeCommand; +import com.cloud.agent.api.to.StorageFilerTO; +import com.cloud.storage.Storage; +import com.cloud.storage.StoragePool; +import com.cloud.storage.StoragePoolStatus; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -26,6 +32,10 @@ import org.mockito.Mockito; import com.cloud.agent.api.CheckNetworkAnswer; import com.cloud.agent.api.CheckNetworkCommand; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + public class CheckNetworkAnswerTest { CheckNetworkCommand cnc; CheckNetworkAnswer cna; @@ -59,4 +69,199 @@ public class CheckNetworkAnswerTest { boolean b = cna.executeInSequence(); assertFalse(b); } + + public static class ResizeVolumeCommandTest { + + public StoragePool dummypool = new StoragePool() { + @Override + public long getId() { + return 1L; + }; + + @Override + public String getName() { + return "name"; + }; + + @Override + public String getUuid() { + return "bed9f83e-cac3-11e1-ac8a-0050568b007e"; + }; + + @Override + public Storage.StoragePoolType getPoolType() { + return Storage.StoragePoolType.Filesystem; + }; + + @Override + public Date getCreated() { + Date date = null; + try { + date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss") + .parse("01/01/1970 12:12:12"); + } catch (ParseException e) { + e.printStackTrace(); + } + return date; + } + + @Override + public Date getUpdateTime() { + return new Date(); + }; + + @Override + public long getDataCenterId() { + return 0L; + }; + + @Override + public long getCapacityBytes() { + return 0L; + }; + + @Override + public long getUsedBytes() { + return 0L; + }; + + @Override + public Long getClusterId() { + return 0L; + }; + + @Override + public String getHostAddress() { + return "hostAddress"; + }; + + @Override + public String getPath() { + return "path"; + }; + + @Override + public String getUserInfo() { + return "userInfo"; + }; + + @Override + public boolean isShared() { + return false; + }; + + @Override + public boolean isLocal() { + return false; + }; + + @Override + public StoragePoolStatus getStatus() { + return StoragePoolStatus.Up; + }; + + @Override + public int getPort() { + return 25; + }; + + @Override + public Long getPodId() { + return 0L; + } + + @Override + public String getStorageProviderName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isInMaintenance() { + // TODO Auto-generated method stub + return false; + }; + }; + + Long newSize = 4194304L; + Long currentSize = 1048576L; + + ResizeVolumeCommand rv = new ResizeVolumeCommand("dummydiskpath", + new StorageFilerTO(dummypool), currentSize, newSize, false, + "vmName"); + + @Test + public void testExecuteInSequence() { + boolean b = rv.executeInSequence(); + assertFalse(b); + } + + @Test + public void testGetPath() { + String path = rv.getPath(); + assertTrue(path.equals("dummydiskpath")); + } + + @Test + public void testGetPoolUuid() { + String poolUuid = rv.getPoolUuid(); + assertTrue(poolUuid.equals("bed9f83e-cac3-11e1-ac8a-0050568b007e")); + } + + @Test + public void testGetPool() { + StorageFilerTO pool = rv.getPool(); + + Long id = pool.getId(); + Long expectedL = 1L; + assertEquals(expectedL, id); + + String uuid = pool.getUuid(); + assertTrue(uuid.equals("bed9f83e-cac3-11e1-ac8a-0050568b007e")); + + String host = pool.getHost(); + assertTrue(host.equals("hostAddress")); + + String path = pool.getPath(); + assertTrue(path.equals("path")); + + String userInfo = pool.getUserInfo(); + assertTrue(userInfo.equals("userInfo")); + + Integer port = pool.getPort(); + Integer expectedI = 25; + assertEquals(expectedI, port); + + Storage.StoragePoolType type = pool.getType(); + assertEquals(Storage.StoragePoolType.Filesystem, type); + + String str = pool.toString(); + assertTrue(str.equals("Pool[" + id.toString() + "|" + host + ":" + + port.toString() + "|" + path + "]")); + } + + @Test + public void testGetNewSize() { + long newSize = rv.getNewSize(); + assertTrue(newSize == 4194304L); + } + + @Test + public void testGetCurrentSize() { + long currentSize = rv.getCurrentSize(); + assertTrue(currentSize == 1048576L); + } + + @Test + public void testGetShrinkOk() { + assertFalse(rv.getShrinkOk()); + } + + @Test + public void testGetInstanceName() { + String vmName = rv.getInstanceName(); + assertTrue(vmName.equals("vmName")); + } + + } } diff --git a/core/test/org/apache/cloudstack/api/agent/test/SnapshotCommandTest.java b/core/test/org/apache/cloudstack/api/agent/test/SnapshotCommandTest.java index 56a1d221357..3076d453434 100644 --- a/core/test/org/apache/cloudstack/api/agent/test/SnapshotCommandTest.java +++ b/core/test/org/apache/cloudstack/api/agent/test/SnapshotCommandTest.java @@ -74,7 +74,7 @@ public class SnapshotCommandTest { return 0L; }; - public long getAvailableBytes() { + public long getUsedBytes() { return 0L; }; diff --git a/core/test/src/com/cloud/agent/api/test/ResizeVolumeCommandTest.java b/core/test/src/com/cloud/agent/api/test/ResizeVolumeCommandTest.java deleted file mode 100644 index 02085f577b6..00000000000 --- a/core/test/src/com/cloud/agent/api/test/ResizeVolumeCommandTest.java +++ /dev/null @@ -1,229 +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 src.com.cloud.agent.api.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.junit.Test; - -import com.cloud.agent.api.storage.ResizeVolumeCommand; -import com.cloud.agent.api.to.StorageFilerTO; -import com.cloud.storage.Storage.StoragePoolType; -import com.cloud.storage.StoragePool; -import com.cloud.storage.StoragePoolStatus; - - -public class ResizeVolumeCommandTest { - - public StoragePool dummypool = new StoragePool() { - @Override - public long getId() { - return 1L; - }; - - @Override - public String getName() { - return "name"; - }; - - @Override - public String getUuid() { - return "bed9f83e-cac3-11e1-ac8a-0050568b007e"; - }; - - @Override - public StoragePoolType getPoolType() { - return StoragePoolType.Filesystem; - }; - - @Override - public Date getCreated() { - Date date = null; - try { - date = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss") - .parse("01/01/1970 12:12:12"); - } catch (ParseException e) { - e.printStackTrace(); - } - return date; - } - - @Override - public Date getUpdateTime() { - return new Date(); - }; - - @Override - public long getDataCenterId() { - return 0L; - }; - - @Override - public long getCapacityBytes() { - return 0L; - }; - - @Override - public long getAvailableBytes() { - return 0L; - }; - - @Override - public Long getClusterId() { - return 0L; - }; - - @Override - public String getHostAddress() { - return "hostAddress"; - }; - - @Override - public String getPath() { - return "path"; - }; - - @Override - public String getUserInfo() { - return "userInfo"; - }; - - @Override - public boolean isShared() { - return false; - }; - - @Override - public boolean isLocal() { - return false; - }; - - @Override - public StoragePoolStatus getStatus() { - return StoragePoolStatus.Up; - }; - - @Override - public int getPort() { - return 25; - }; - - @Override - public Long getPodId() { - return 0L; - } - - @Override - public String getStorageProviderName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean isInMaintenance() { - // TODO Auto-generated method stub - return false; - }; - }; - - Long newSize = 4194304L; - Long currentSize = 1048576L; - - ResizeVolumeCommand rv = new ResizeVolumeCommand("dummydiskpath", - new StorageFilerTO(dummypool), currentSize, newSize, false, - "vmName"); - - @Test - public void testExecuteInSequence() { - boolean b = rv.executeInSequence(); - assertFalse(b); - } - - @Test - public void testGetPath() { - String path = rv.getPath(); - assertTrue(path.equals("dummydiskpath")); - } - - @Test - public void testGetPoolUuid() { - String poolUuid = rv.getPoolUuid(); - assertTrue(poolUuid.equals("bed9f83e-cac3-11e1-ac8a-0050568b007e")); - } - - @Test - public void testGetPool() { - StorageFilerTO pool = rv.getPool(); - - Long id = pool.getId(); - Long expectedL = 1L; - assertEquals(expectedL, id); - - String uuid = pool.getUuid(); - assertTrue(uuid.equals("bed9f83e-cac3-11e1-ac8a-0050568b007e")); - - String host = pool.getHost(); - assertTrue(host.equals("hostAddress")); - - String path = pool.getPath(); - assertTrue(path.equals("path")); - - String userInfo = pool.getUserInfo(); - assertTrue(userInfo.equals("userInfo")); - - Integer port = pool.getPort(); - Integer expectedI = 25; - assertEquals(expectedI, port); - - StoragePoolType type = pool.getType(); - assertEquals(StoragePoolType.Filesystem, type); - - String str = pool.toString(); - assertTrue(str.equals("Pool[" + id.toString() + "|" + host + ":" - + port.toString() + "|" + path + "]")); - } - - @Test - public void testGetNewSize() { - long newSize = rv.getNewSize(); - assertTrue(newSize == 4194304L); - } - - @Test - public void testGetCurrentSize() { - long currentSize = rv.getCurrentSize(); - assertTrue(currentSize == 1048576L); - } - - @Test - public void testGetShrinkOk() { - assertFalse(rv.getShrinkOk()); - } - - @Test - public void testGetInstanceName() { - String vmName = rv.getInstanceName(); - assertTrue(vmName.equals("vmName")); - } - -} diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java index 15e6d45f9ca..b0ed7d7d52b 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ClusterScope.java @@ -27,6 +27,7 @@ public class ClusterScope extends AbstractScope { private Long zoneId; public ClusterScope(Long clusterId, Long podId, Long zoneId) { + super(); this.clusterId = clusterId; this.podId = podId; this.zoneId = zoneId; diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMigrationSubSystem.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMigrationSubSystem.java deleted file mode 100755 index ad810432fd2..00000000000 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMigrationSubSystem.java +++ /dev/null @@ -1,30 +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.engine.subsystem.api.storage; - -import java.net.URI; - -import com.cloud.org.Grouping; - -public interface DataMigrationSubSystem { - - Class getScopeCoverage(); - - void migrate(URI source, URI dest, String reservationId); -} diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMotionService.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMotionService.java index 5a124aa2725..5e10a0ba7e7 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMotionService.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMotionService.java @@ -26,9 +26,9 @@ import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.host.Host; public interface DataMotionService { - public void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback callback); + void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback callback); - public void copyAsync(Map volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, + void copyAsync(Map volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, AsyncCompletionCallback callback); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMotionStrategy.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMotionStrategy.java index 5bff21f3c8a..6deb6c1afc0 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMotionStrategy.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataMotionStrategy.java @@ -26,13 +26,13 @@ import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.host.Host; public interface DataMotionStrategy { - public boolean canHandle(DataObject srcData, DataObject destData); + boolean canHandle(DataObject srcData, DataObject destData); - public boolean canHandle(Map volumeMap, Host srcHost, Host destHost); + boolean canHandle(Map volumeMap, Host srcHost, Host destHost); - public Void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback callback); + Void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback callback); - public Void copyAsync(Map volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, + Void copyAsync(Map volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, AsyncCompletionCallback callback); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java index 0cd21119a9b..c57b01ce8b0 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java @@ -23,24 +23,29 @@ import com.cloud.agent.api.to.DataObjectType; import com.cloud.agent.api.to.DataTO; public interface DataObject { - public long getId(); + long getId(); - public String getUri(); + String getUri(); - public DataTO getTO(); + DataTO getTO(); - public DataStore getDataStore(); + DataStore getDataStore(); - public Long getSize(); + Long getSize(); - public DataObjectType getType(); + DataObjectType getType(); - // public DiskFormat getFormat(); - public String getUuid(); + String getUuid(); boolean delete(); - public void processEvent(ObjectInDataStoreStateMachine.Event event); + void processEvent(ObjectInDataStoreStateMachine.Event event); - public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer); + void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer); + + void incRefCount(); + + void decRefCount(); + + Long getRefCount(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataObjectInStore.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataObjectInStore.java index 929774c67c9..95bb9b98c44 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataObjectInStore.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataObjectInStore.java @@ -21,13 +21,13 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import com.cloud.utils.fsm.StateObject; public interface DataObjectInStore extends StateObject { - public String getInstallPath(); + String getInstallPath(); - public void setInstallPath(String path); + void setInstallPath(String path); - public long getObjectId(); + long getObjectId(); - public long getDataStoreId(); + long getDataStoreId(); - public ObjectInDataStoreStateMachine.State getObjectInStoreState(); + ObjectInDataStoreStateMachine.State getObjectInStoreState(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreDriver.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreDriver.java index 21430805c67..1cb6e158489 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreDriver.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreDriver.java @@ -18,32 +18,23 @@ */ package org.apache.cloudstack.engine.subsystem.api.storage; -import java.util.Set; - +import com.cloud.agent.api.to.DataStoreTO; +import com.cloud.agent.api.to.DataTO; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.storage.command.CommandResult; -import com.cloud.agent.api.to.DataStoreTO; -import com.cloud.agent.api.to.DataTO; - public interface DataStoreDriver { - public String grantAccess(DataObject data, EndPoint ep); + void createAsync(DataObject data, AsyncCompletionCallback callback); - public boolean revokeAccess(DataObject data, EndPoint ep); + void deleteAsync(DataObject data, AsyncCompletionCallback callback); - public Set listObjects(DataStore store); + void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback callback); - public void createAsync(DataObject data, AsyncCompletionCallback callback); + boolean canCopy(DataObject srcData, DataObject destData); - public void deleteAsync(DataObject data, AsyncCompletionCallback callback); + void resize(DataObject data, AsyncCompletionCallback callback); - public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback callback); + DataTO getTO(DataObject data); - public boolean canCopy(DataObject srcData, DataObject destData); - - public void resize(DataObject data, AsyncCompletionCallback callback); - - public DataTO getTO(DataObject data); - - public DataStoreTO getStoreTO(DataStore store); + DataStoreTO getStoreTO(DataStore store); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreLifeCycle.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreLifeCycle.java index bd8c6e0060c..1e893db6bb5 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreLifeCycle.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreLifeCycle.java @@ -24,21 +24,17 @@ import com.cloud.agent.api.StoragePoolInfo; import com.cloud.hypervisor.Hypervisor.HypervisorType; public interface DataStoreLifeCycle { - public DataStore initialize(Map dsInfos); + DataStore initialize(Map dsInfos); - public boolean attachCluster(DataStore store, ClusterScope scope); + boolean attachCluster(DataStore store, ClusterScope scope); - public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo); + boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo); boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType); - public boolean dettach(); + boolean maintain(DataStore store); - public boolean unmanaged(); + boolean cancelMaintain(DataStore store); - public boolean maintain(DataStore store); - - public boolean cancelMaintain(DataStore store); - - public boolean deleteDataStore(DataStore store); + boolean deleteDataStore(DataStore store); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java index 8617eb4c2ad..949b037c1bd 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java @@ -24,21 +24,17 @@ import java.util.Map; import com.cloud.storage.DataStoreRole; public interface DataStoreManager { - public DataStore getDataStore(long storeId, DataStoreRole role); + DataStore getDataStore(long storeId, DataStoreRole role); - public DataStore getPrimaryDataStore(long storeId); + DataStore getPrimaryDataStore(long storeId); - public DataStore getDataStore(String uuid, DataStoreRole role); + DataStore getDataStore(String uuid, DataStoreRole role); - public List getImageStoresByScope(ZoneScope scope); + List getImageStoresByScope(ZoneScope scope); - public DataStore getImageStore(long zoneId); + DataStore getImageStore(long zoneId); - public List getImageStoresByProvider(String provider); + List getImageCacheStores(Scope scope); - public List getImageCacheStores(Scope scope); - - public DataStore registerDataStore(Map params, String providerUuid); - - public List listImageStores(); + List listImageStores(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProvider.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProvider.java index a13c60bd772..855f0854103 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProvider.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProvider.java @@ -23,27 +23,26 @@ import java.util.Set; public interface DataStoreProvider { // constants for provider names - public static final String NFS_IMAGE = "NFS"; - public static final String S3_IMAGE = "S3"; - public static final String SWIFT_IMAGE = "Swift"; - public static final String SAMPLE_IMAGE = "Sample"; + static final String NFS_IMAGE = "NFS"; + static final String S3_IMAGE = "S3"; + static final String SWIFT_IMAGE = "Swift"; + static final String SAMPLE_IMAGE = "Sample"; - public static final String DEFAULT_PRIMARY = "DefaultPrimary"; + static final String DEFAULT_PRIMARY = "DefaultPrimary"; - public static enum DataStoreProviderType { + static enum DataStoreProviderType { PRIMARY, IMAGE, ImageCache } - public DataStoreLifeCycle getDataStoreLifeCycle(); + DataStoreLifeCycle getDataStoreLifeCycle(); - public DataStoreDriver getDataStoreDriver(); + DataStoreDriver getDataStoreDriver(); - public HypervisorHostListener getHostListener(); + HypervisorHostListener getHostListener(); - public String getName(); + String getName(); - public boolean configure(Map params); - - public Set getTypes(); + boolean configure(Map params); + Set getTypes(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProviderManager.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProviderManager.java index 84272ef412c..d25e10ed34a 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProviderManager.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProviderManager.java @@ -24,14 +24,11 @@ import com.cloud.storage.DataStoreProviderApiService; import com.cloud.utils.component.Manager; public interface DataStoreProviderManager extends Manager, DataStoreProviderApiService { - public DataStoreProvider getDataStoreProvider(String name); + DataStoreProvider getDataStoreProvider(String name); - public DataStoreProvider getDefaultPrimaryDataStoreProvider(); + DataStoreProvider getDefaultPrimaryDataStoreProvider(); - public DataStoreProvider getDefaultImageDataStoreProvider(); - - public DataStoreProvider getDefaultCacheDataStoreProvider(); - - public List getDataStoreProviders(); + DataStoreProvider getDefaultImageDataStoreProvider(); + DataStoreProvider getDefaultCacheDataStoreProvider(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPoint.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPoint.java index ed9c0ebe908..254c91d3544 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPoint.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPoint.java @@ -22,13 +22,13 @@ import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; public interface EndPoint { - public long getId(); + long getId(); - public String getHostAddr(); + String getHostAddr(); - public String getPublicAddr(); + String getPublicAddr(); - public Answer sendMessage(Command cmd); + Answer sendMessage(Command cmd); - public void sendMessageAsync(Command cmd, AsyncCompletionCallback callback); + void sendMessageAsync(Command cmd, AsyncCompletionCallback callback); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java index a51fad817c0..ca0cc2c970a 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java @@ -21,19 +21,11 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import java.util.List; public interface EndPointSelector { - public EndPoint select(DataObject srcData, DataObject destData); + EndPoint select(DataObject srcData, DataObject destData); - /** - * @param object - * @return - */ EndPoint select(DataObject object); EndPoint select(DataStore store); - /** - * @param store - * @return - */ List selectAll(DataStore store); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java index ff33077146a..1ff381872e6 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HostScope.java @@ -25,6 +25,7 @@ public class HostScope extends AbstractScope { private Long zoneId; public HostScope(Long hostId, Long zoneId) { + super(); this.hostId = hostId; this.zoneId = zoneId; } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageStoreProvider.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageStoreProvider.java index bde4fe4c597..0025ae1cde6 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageStoreProvider.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageStoreProvider.java @@ -22,7 +22,7 @@ import com.cloud.storage.ScopeType; public interface ImageStoreProvider extends DataStoreProvider { - public boolean isScopeSupported(ScopeType scope); + boolean isScopeSupported(ScopeType scope); - public boolean needDownloadSysTemplate(); + boolean needDownloadSysTemplate(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java index ee355573a6c..2528a536d64 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java @@ -22,7 +22,7 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.storage.command.CommandResult; public interface PrimaryDataStoreDriver extends DataStoreDriver { - public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback); + void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback); - public void revertSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback); + void revertSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java index c69cd3a75cb..95a5cc9778b 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java @@ -25,15 +25,15 @@ import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.StoragePool; public interface PrimaryDataStoreInfo extends StoragePool { - public boolean isHypervisorSupported(HypervisorType hypervisor); + boolean isHypervisorSupported(HypervisorType hypervisor); - public boolean isLocalStorageSupported(); + boolean isLocalStorageSupported(); - public boolean isVolumeDiskTypeSupported(DiskFormat diskType); + boolean isVolumeDiskTypeSupported(DiskFormat diskType); - public String getUuid(); + String getUuid(); - public StoragePoolType getPoolType(); + StoragePoolType getPoolType(); - public PrimaryDataStoreLifeCycle getLifeCycle(); + PrimaryDataStoreLifeCycle getLifeCycle(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java index 5c71f3cc220..8e43fa07fd8 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/Scope.java @@ -21,9 +21,9 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import com.cloud.storage.ScopeType; public interface Scope { - public ScopeType getScopeType(); + ScopeType getScopeType(); - public boolean isSameScope(Scope scope); + boolean isSameScope(Scope scope); - public Long getScopeId(); + Long getScopeId(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java index 04b67d427c1..0b8d1f104e1 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java @@ -21,9 +21,9 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import com.cloud.storage.DataStoreRole; public interface SnapshotDataFactory { - public SnapshotInfo getSnapshot(long snapshotId, DataStore store); + SnapshotInfo getSnapshot(long snapshotId, DataStore store); - public SnapshotInfo getSnapshot(DataObject obj, DataStore store); + SnapshotInfo getSnapshot(DataObject obj, DataStore store); - public SnapshotInfo getSnapshot(long snapshotId, DataStoreRole role); + SnapshotInfo getSnapshot(long snapshotId, DataStoreRole role); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java index 91e0fd79fa9..8d6b76010fe 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java @@ -19,15 +19,15 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import com.cloud.storage.Snapshot; public interface SnapshotInfo extends DataObject, Snapshot { - public SnapshotInfo getParent(); + SnapshotInfo getParent(); - public String getPath(); + String getPath(); - public SnapshotInfo getChild(); + SnapshotInfo getChild(); - public VolumeInfo getBaseVolume(); + VolumeInfo getBaseVolume(); - public void addPayload(Object data); + void addPayload(Object data); Long getDataCenterId(); diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotService.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotService.java index 67c88471dfc..d594a0728cb 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotService.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotService.java @@ -18,11 +18,11 @@ package org.apache.cloudstack.engine.subsystem.api.storage; public interface SnapshotService { - public SnapshotResult takeSnapshot(SnapshotInfo snapshot); + SnapshotResult takeSnapshot(SnapshotInfo snapshot); - public SnapshotInfo backupSnapshot(SnapshotInfo snapshot); + SnapshotInfo backupSnapshot(SnapshotInfo snapshot); - public boolean deleteSnapshot(SnapshotInfo snapshot); + boolean deleteSnapshot(SnapshotInfo snapshot); - public boolean revertSnapshot(SnapshotInfo snapshot); + boolean revertSnapshot(SnapshotInfo snapshot); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotStrategy.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotStrategy.java index 542246ae36f..86ae532e2dc 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotStrategy.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotStrategy.java @@ -19,15 +19,11 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import com.cloud.storage.Snapshot; public interface SnapshotStrategy { - public SnapshotInfo takeSnapshot(SnapshotInfo snapshot); + SnapshotInfo takeSnapshot(SnapshotInfo snapshot); - public SnapshotInfo backupSnapshot(SnapshotInfo snapshot); + SnapshotInfo backupSnapshot(SnapshotInfo snapshot); - public boolean deleteSnapshot(Long snapshotId); + boolean deleteSnapshot(Long snapshotId); - /** - * @param snapshot - * @return - */ boolean canHandle(Snapshot snapshot); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java index fd5211f1dd0..92724c91889 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageCacheManager.java @@ -19,9 +19,9 @@ package org.apache.cloudstack.engine.subsystem.api.storage; public interface StorageCacheManager { - public DataStore getCacheStorage(Scope scope); + DataStore getCacheStorage(Scope scope); - public DataObject createCacheObject(DataObject data, Scope scope); + DataObject createCacheObject(DataObject data, Scope scope); /** * only create cache object in db @@ -33,4 +33,8 @@ public interface StorageCacheManager { DataObject getCacheObject(DataObject data, Scope scope); boolean deleteCacheObject(DataObject data); + + boolean releaseCacheObject(DataObject data); + + DataObject createCacheObject(DataObject data, DataStore store); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageOrchestrator.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageOrchestrator.java deleted file mode 100755 index d4455c8059a..00000000000 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageOrchestrator.java +++ /dev/null @@ -1,76 +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.engine.subsystem.api.storage; - -import java.util.List; - -import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity; -import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; -import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat; -import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType; - -import com.cloud.deploy.DeploymentPlan; - -public interface StorageOrchestrator { - - /** - * Prepares all storage ready for a VM to start - * - * @param vm - * @param reservationId - */ - void prepare(long vmId, DeploymentPlan plan, String reservationId); - - /** - * Releases all storage that were used for a VM shutdown - * - * @param vm - * @param disks - * @param reservationId - */ - void release(long vmId, String reservationId); - - /** - * Destroy all disks - * - * @param disks - * @param reservationId - */ - void destroy(List disks, String reservationId); - - /** - * Cancel a reservation - * - * @param reservationId - * reservation to - */ - void cancel(String reservationId); - - /** - * If attaching a volume in allocated state to a running vm, need to create - * this volume - */ - void prepareAttachDiskToVM(long diskId, long vmId, String reservationId); - - boolean createVolume(VolumeEntity volume, long dataStoreId, DiskFormat diskType); - - boolean createVolumeFromTemplate(VolumeEntity volume, long dataStoreId, DiskFormat dis, TemplateEntity template); - - VolumeEntity allocateVolumeInDb(long size, VolumeType type, String volName, Long templateId); -} diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java index 13eb0de6f70..eccf0f4f6e1 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java @@ -47,5 +47,5 @@ public interface StoragePoolAllocator extends Adapter { List allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo); - public static int RETURN_UPTO_ALL = -1; + static int RETURN_UPTO_ALL = -1; } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageSubSystem.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageSubSystem.java deleted file mode 100644 index e5a74a452a1..00000000000 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageSubSystem.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 org.apache.cloudstack.engine.subsystem.api.storage; - -import java.net.URI; - -import com.cloud.org.Grouping; - -public interface StorageSubSystem { - String getType(); - - Class getScope(); - - URI grantAccess(String vol, String reservationId); - - URI RemoveAccess(String vol, String reservationId); -} diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java index 91dba115e09..ceb5fc0f55b 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java @@ -21,7 +21,7 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import com.cloud.template.VirtualMachineTemplate; public interface TemplateInfo extends DataObject, VirtualMachineTemplate { - public String getUniqueName(); + String getUniqueName(); - public String getInstallPath(); + String getInstallPath(); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateProfile.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateProfile.java deleted file mode 100755 index dcfd4074bfd..00000000000 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateProfile.java +++ /dev/null @@ -1,312 +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.engine.subsystem.api.storage; - -import java.util.Map; - -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.storage.Storage.ImageFormat; -import com.cloud.template.VirtualMachineTemplate; - -public class TemplateProfile { - Long userId; - String name; - String displayText; - Integer bits; - Boolean passwordEnabled; - Boolean sshKeyEnbaled; - Boolean requiresHvm; - String url; - Boolean isPublic; - Boolean featured; - Boolean isExtractable; - ImageFormat format; - Long guestOsId; - Long zoneId; - HypervisorType hypervisorType; - String accountName; - Long domainId; - Long accountId; - String chksum; - Boolean bootable; - Long templateId; - VirtualMachineTemplate template; - String templateTag; - Map details; - - public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, - Boolean passwordEnabled, Boolean requiresHvm, String url, Boolean isPublic, Boolean featured, - Boolean isExtractable, ImageFormat format, Long guestOsId, Long zoneId, HypervisorType hypervisorType, - String accountName, Long domainId, Long accountId, String chksum, Boolean bootable, Map details, - Boolean sshKeyEnabled) { - this.templateId = templateId; - this.userId = userId; - this.name = name; - this.displayText = displayText; - this.bits = bits; - this.passwordEnabled = passwordEnabled; - this.requiresHvm = requiresHvm; - this.url = url; - this.isPublic = isPublic; - this.featured = featured; - this.isExtractable = isExtractable; - this.format = format; - this.guestOsId = guestOsId; - this.zoneId = zoneId; - this.hypervisorType = hypervisorType; - this.accountName = accountName; - this.domainId = domainId; - this.accountId = accountId; - this.chksum = chksum; - this.bootable = bootable; - this.details = details; - this.sshKeyEnbaled = sshKeyEnabled; - } - - public TemplateProfile(Long userId, VirtualMachineTemplate template, Long zoneId) { - this.userId = userId; - this.template = template; - this.zoneId = zoneId; - } - - public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, - Boolean passwordEnabled, Boolean requiresHvm, String url, Boolean isPublic, Boolean featured, - Boolean isExtractable, ImageFormat format, Long guestOsId, Long zoneId, HypervisorType hypervisorType, - String accountName, Long domainId, Long accountId, String chksum, Boolean bootable, String templateTag, - Map details, Boolean sshKeyEnabled) { - this(templateId, userId, name, displayText, bits, passwordEnabled, requiresHvm, url, isPublic, featured, - isExtractable, format, guestOsId, zoneId, hypervisorType, accountName, domainId, accountId, chksum, - bootable, details, sshKeyEnabled); - this.templateTag = templateTag; - } - - public Long getTemplateId() { - return templateId; - } - - public void setTemplateId(Long id) { - this.templateId = id; - } - - public Long getUserId() { - return userId; - } - - public void setUserId(Long userId) { - this.userId = userId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDisplayText() { - return displayText; - } - - public void setDisplayText(String text) { - this.displayText = text; - } - - public Integer getBits() { - return bits; - } - - public void setBits(Integer bits) { - this.bits = bits; - } - - public Boolean getPasswordEnabled() { - return passwordEnabled; - } - - public void setPasswordEnabled(Boolean enabled) { - this.passwordEnabled = enabled; - } - - public Boolean getRequiresHVM() { - return requiresHvm; - } - - public void setRequiresHVM(Boolean hvm) { - this.requiresHvm = hvm; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Boolean getIsPublic() { - return isPublic; - } - - public void setIsPublic(Boolean is) { - this.isPublic = is; - } - - public Boolean getFeatured() { - return featured; - } - - public void setFeatured(Boolean featured) { - this.featured = featured; - } - - public Boolean getIsExtractable() { - return isExtractable; - } - - public void setIsExtractable(Boolean is) { - this.isExtractable = is; - } - - public ImageFormat getFormat() { - return format; - } - - public void setFormat(ImageFormat format) { - this.format = format; - } - - public Long getGuestOsId() { - return guestOsId; - } - - public void setGuestOsId(Long id) { - this.guestOsId = id; - } - - public Long getZoneId() { - return zoneId; - } - - public void setZoneId(Long id) { - this.zoneId = id; - } - - public HypervisorType getHypervisorType() { - return hypervisorType; - } - - public void setHypervisorType(HypervisorType type) { - this.hypervisorType = type; - } - - public Long getDomainId() { - return domainId; - } - - public void setDomainId(Long id) { - this.domainId = id; - } - - public Long getAccountId() { - return accountId; - } - - public void setAccountId(Long id) { - this.accountId = id; - } - - public String getCheckSum() { - return chksum; - } - - public void setCheckSum(String chksum) { - this.chksum = chksum; - } - - public Boolean getBootable() { - return this.bootable; - } - - public void setBootable(Boolean bootable) { - this.bootable = bootable; - } - - public VirtualMachineTemplate getTemplate() { - return template; - } - - public void setTemplate(VirtualMachineTemplate template) { - this.template = template; - } - - public String getTemplateTag() { - return templateTag; - } - - public void setTemplateTag(String templateTag) { - this.templateTag = templateTag; - } - - public Map getDetails() { - return this.details; - } - - public void setDetails(Map details) { - this.details = details; - } - - public void setSshKeyEnabled(Boolean enabled) { - this.sshKeyEnbaled = enabled; - } - - public Boolean getSshKeyEnabled() { - return this.sshKeyEnbaled; - } - - public String getImageStorageUri() { - return null; - } - - public void setLocalPath(String path) { - - } - - public String getLocalPath() { - return null; - } - - public String getJobId() { - return null; - } - - public void setTemplatePoolRefId(long id) { - - } - - public long getId() { - return 0; - } - - public long getTemplatePoolRefId() { - return 0; - } - - public long getSize() { - return 0; - } -} diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java index 52e18f195f1..085fbbdb232 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateService.java @@ -27,7 +27,7 @@ import com.cloud.storage.StoragePool; public interface TemplateService { - public class TemplateApiResult extends CommandResult { + class TemplateApiResult extends CommandResult { private final TemplateInfo template; public TemplateApiResult(TemplateInfo template) { diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java index 463c0ff3538..3d7b1aa76cb 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java @@ -23,21 +23,21 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.Volume; public interface VolumeInfo extends DataObject, Volume { - public boolean isAttachedVM(); + boolean isAttachedVM(); - public void addPayload(Object data); + void addPayload(Object data); - public Object getpayload(); + Object getpayload(); - public HypervisorType getHypervisorType(); + HypervisorType getHypervisorType(); - public Long getLastPoolId(); + Long getLastPoolId(); - public String getAttachedVmName(); + String getAttachedVmName(); - public void processEventOnly(ObjectInDataStoreStateMachine.Event event); + void processEventOnly(ObjectInDataStoreStateMachine.Event event); - public void processEventOnly(ObjectInDataStoreStateMachine.Event event, Answer answer); + void processEventOnly(ObjectInDataStoreStateMachine.Event event, Answer answer); - public boolean stateTransit(Volume.Event event); + boolean stateTransit(Volume.Event event); } diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeProfile.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeProfile.java deleted file mode 100644 index 8701912f304..00000000000 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeProfile.java +++ /dev/null @@ -1,35 +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.engine.subsystem.api.storage; - -public class VolumeProfile { - private String _uri; - - public String getURI() { - return _uri; - } - - public String getPath() { - return null; - } - - public long getSize() { - return 0; - } -} diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java index 39479523271..f96ea4032d1 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java @@ -29,8 +29,7 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.host.Host; public interface VolumeService { - - public class VolumeApiResult extends CommandResult { + class VolumeApiResult extends CommandResult { private final VolumeInfo volume; public VolumeApiResult(VolumeInfo volume) { diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java index 9ba1d10012a..a0d75b5cc7c 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ZoneScope.java @@ -25,6 +25,7 @@ public class ZoneScope extends AbstractScope { private Long zoneId; public ZoneScope(Long zoneId) { + super(); this.zoneId = zoneId; } diff --git a/engine/api/src/org/apache/cloudstack/storage/command/CreateObjectCommand.java b/engine/api/src/org/apache/cloudstack/storage/command/CreateObjectCommand.java index a282a51e78a..121a7ee449c 100644 --- a/engine/api/src/org/apache/cloudstack/storage/command/CreateObjectCommand.java +++ b/engine/api/src/org/apache/cloudstack/storage/command/CreateObjectCommand.java @@ -35,7 +35,6 @@ public final class CreateObjectCommand extends Command implements StorageSubSyst @Override public boolean executeInSequence() { - // TODO Auto-generated method stub return false; } diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java index 8d63a82be69..70e9bb386e0 100644 --- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java +++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java @@ -25,13 +25,13 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; import com.cloud.utils.db.GenericDao; public interface ImageStoreDao extends GenericDao { - public ImageStoreVO findByName(String name); + ImageStoreVO findByName(String name); - public List findByProvider(String provider); + List findByProvider(String provider); - public List findByScope(ZoneScope scope); + List findByScope(ZoneScope scope); - public List findImageCacheByScope(ZoneScope scope); + List findImageCacheByScope(ZoneScope scope); - public List listImageStores(); + List listImageStores(); } diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java index 3c903ad6e20..5ed48a3781c 100644 --- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java +++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java @@ -80,6 +80,9 @@ public class ImageStoreVO implements ImageStore { @Column(name = "total_size") private Long totalSize; + @Column(name = "used_bytes") + private Long usedBytes; + public DataStoreRole getRole() { return role; } @@ -180,4 +183,11 @@ public class ImageStoreVO implements ImageStore { this.totalSize = totalSize; } + public Long getUsedBytes() { + return usedBytes; + } + + public void setUsedBytes(Long usedBytes) { + this.usedBytes = usedBytes; + } } diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java index 08082870268..8f7826f4006 100644 --- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java +++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -147,7 +147,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase @Override public void updateAvailable(long id, long available) { StoragePoolVO pool = createForUpdate(id); - pool.setAvailableBytes(available); + pool.setUsedBytes(available); update(id, pool); } diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java index 48d0db28127..01f02208307 100644 --- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java +++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java @@ -28,13 +28,13 @@ import com.cloud.utils.fsm.StateDao; public interface SnapshotDataStoreDao extends GenericDao, StateDao { - public List listByStoreId(long id, DataStoreRole role); + List listByStoreId(long id, DataStoreRole role); - public void deletePrimaryRecordsForStore(long id); + void deletePrimaryRecordsForStore(long id); - public SnapshotDataStoreVO findByStoreSnapshot(DataStoreRole role, long storeId, long snapshotId); + SnapshotDataStoreVO findByStoreSnapshot(DataStoreRole role, long storeId, long snapshotId); - public SnapshotDataStoreVO findBySnapshot(long snapshotId, DataStoreRole role); + SnapshotDataStoreVO findBySnapshot(long snapshotId, DataStoreRole role); - public List listDestroyed(long storeId); + List listDestroyed(long storeId); } diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java index 6ceb0d0fcba..2ae3e8cdbda 100644 --- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java +++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java @@ -92,6 +92,9 @@ public class SnapshotDataStoreVO implements StateObject, StateDao { - public List listByStoreId(long id); + List listByStoreId(long id); - public List listDestroyed(long storeId); + List listDestroyed(long storeId); - public void deletePrimaryRecordsForStore(long id); + void deletePrimaryRecordsForStore(long id); - public void deletePrimaryRecordsForTemplate(long templateId); + void deletePrimaryRecordsForTemplate(long templateId); List listByTemplateStore(long templateId, long storeId); diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreVO.java index 2cee4d13e8e..c6b434dbc1a 100755 --- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreVO.java +++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreVO.java @@ -71,7 +71,7 @@ public class TemplateDataStoreVO implements StateObject, StateDao { - public List listByStoreId(long id); + List listByStoreId(long id); - public void deletePrimaryRecordsForStore(long id); + void deletePrimaryRecordsForStore(long id); - public VolumeDataStoreVO findByVolume(long volumeId); + VolumeDataStoreVO findByVolume(long volumeId); - public VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId); + VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId); - public VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId, boolean lock); + VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId, boolean lock); - public List listDestroyed(long storeId); + List listDestroyed(long storeId); } diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java index d2e5c2585e1..222447fa4a5 100755 --- a/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java +++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java @@ -111,6 +111,9 @@ public class VolumeDataStoreVO implements StateObject getCacheStores() { + SearchCriteriaService sc = SearchCriteria2.create(ImageStoreVO.class); + sc.addAnd(sc.getEntity().getRole(), SearchCriteria.Op.EQ, DataStoreRole.ImageCache); + List imageStoreVOs = sc.list(); + List stores = new ArrayList(); + for (ImageStoreVO vo : imageStoreVOs) { + stores.add(dataStoreManager.getDataStore(vo.getId(), vo.getRole())); + } + return stores; + } + @Override public String getName() { // TODO Auto-generated method stub @@ -103,12 +124,59 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { @Override public boolean configure(String name, Map params) throws ConfigurationException { - // TODO Auto-generated method stub + cacheReplacementEnabled = Boolean.parseBoolean(configDao.getValue(Config.StorageCacheReplacementEnabled.key())); + cacheReplaceMentInterval = NumbersUtil.parseInt(configDao.getValue(Config.StorageCacheReplacementInterval.key()), 86400); + workers = NumbersUtil.parseInt(configDao.getValue(Config.ExpungeWorkers.key()), 10); + executors = Executors.newScheduledThreadPool(workers, new NamedThreadFactory("StorageCacheManager-cache-replacement")); return true; } + protected class CacheReplacementRunner implements Runnable { + + @Override + public void run() { + GlobalLock replacementLock = null; + try { + replacementLock = GlobalLock.getInternLock("storageCacheMgr.replacement"); + if (replacementLock.lock(3)) { + List stores = getCacheStores(); + Collections.shuffle(stores); + DataObject object = null; + DataStore findAStore = null; + for (DataStore store : stores) { + object = cacheReplacementAlgorithm.chooseOneToBeReplaced(store); + findAStore = store; + if (object != null) { + break; + } + } + + if (object == null) { + return; + } + + while(object != null) { + object.delete(); + object = cacheReplacementAlgorithm.chooseOneToBeReplaced(findAStore); + } + } + } catch (Exception e) { + s_logger.debug("Failed to execute CacheReplacementRunner: " + e.toString()); + } finally { + if (replacementLock != null) { + replacementLock.unlock(); + } + } + } + } + @Override public boolean start() { + if (cacheReplacementEnabled) { + Random generator = new Random(); + int initalDelay = generator.nextInt(cacheReplaceMentInterval); + executors.scheduleWithFixedDelay(new CacheReplacementRunner(), initalDelay, cacheReplaceMentInterval, TimeUnit.SECONDS); + } return true; } @@ -118,29 +186,17 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { return true; } - private class CreateCacheObjectContext extends AsyncRpcConext { - final AsyncCallFuture future; - - /** - * @param callback - */ - public CreateCacheObjectContext(AsyncCompletionCallback callback, AsyncCallFuture future) { - super(callback); - this.future = future; - } - - } - @Override - public DataObject createCacheObject(DataObject data, Scope scope) { - DataStore cacheStore = this.getCacheStorage(scope); - DataObjectInStore obj = objectInStoreMgr.findObject(data, cacheStore); + public DataObject createCacheObject(DataObject data, DataStore store) { + DataObjectInStore obj = objectInStoreMgr.findObject(data, store); if (obj != null && obj.getState() == ObjectInDataStoreStateMachine.State.Ready) { s_logger.debug("there is already one in the cache store"); - return objectInStoreMgr.get(data, cacheStore); + DataObject dataObj = objectInStoreMgr.get(data, store); + dataObj.incRefCount(); + return dataObj; } - DataObject objOnCacheStore = cacheStore.create(data); + DataObject objOnCacheStore = store.create(data); AsyncCallFuture future = new AsyncCallFuture(); CopyCommandResult result = null; @@ -154,6 +210,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { objOnCacheStore.processEvent(Event.OperationFailed); } else { objOnCacheStore.processEvent(Event.OperationSuccessed, result.getAnswer()); + objOnCacheStore.incRefCount(); return objOnCacheStore; } } catch (InterruptedException e) { @@ -167,28 +224,31 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { objOnCacheStore.processEvent(Event.OperationFailed); } } - return null; } + @Override + public DataObject createCacheObject(DataObject data, Scope scope) { + DataStore cacheStore = this.getCacheStorage(scope); + return this.createCacheObject(data, cacheStore); + } + @Override public DataObject getCacheObject(DataObject data, Scope scope) { DataStore cacheStore = this.getCacheStorage(scope); DataObject objOnCacheStore = cacheStore.create(data); - + objOnCacheStore.incRefCount(); return objOnCacheStore; } - protected Void createCacheObjectCallBack( - AsyncCallbackDispatcher callback, - CreateCacheObjectContext context) { - AsyncCallFuture future = context.future; - future.complete(callback.getResult()); - return null; + @Override + public boolean releaseCacheObject(DataObject data) { + data.decRefCount(); + return true; } @Override public boolean deleteCacheObject(DataObject data) { - return objectInStoreMgr.delete(data); + return data.getDataStore().delete(data); } } \ No newline at end of file diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/DataMotionDriver.java b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheReplacementAlgorithm.java similarity index 79% rename from engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/DataMotionDriver.java rename to engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheReplacementAlgorithm.java index 3a59b21238b..f7a23febecd 100644 --- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/DataMotionDriver.java +++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheReplacementAlgorithm.java @@ -16,10 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.cloudstack.storage.motion; +package org.apache.cloudstack.storage.cache.manager; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; -public interface DataMotionDriver { - public void copy(DataObject srcObj, DataObject destObj); +public interface StorageCacheReplacementAlgorithm { + DataObject chooseOneToBeReplaced(DataStore store); } diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheReplacementAlgorithmLRU.java b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheReplacementAlgorithmLRU.java new file mode 100644 index 00000000000..440bf53ebda --- /dev/null +++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheReplacementAlgorithmLRU.java @@ -0,0 +1,106 @@ +/* + * 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.cache.manager; +import com.cloud.configuration.Config; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.utils.DateUtil; +import com.cloud.utils.NumbersUtil; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria2; +import com.cloud.utils.db.SearchCriteriaService; +import org.apache.cloudstack.engine.subsystem.api.storage.*; +import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; +import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; +import org.apache.commons.lang.math.NumberUtils; + +import java.util.Calendar; +import java.util.Date; +import javax.annotation.PostConstruct; +import javax.inject.Inject; + + + +public class StorageCacheReplacementAlgorithmLRU implements StorageCacheReplacementAlgorithm { + @Inject + ConfigurationDao configDao; + @Inject + TemplateDataFactory templateFactory; + @Inject + VolumeDataFactory volumeFactory; + @Inject + SnapshotDataFactory snapshotFactory; + + Integer unusedTimeInterval; + + public StorageCacheReplacementAlgorithmLRU() { + + } + + @PostConstruct + public void initialize() { + unusedTimeInterval = NumbersUtil.parseInt(configDao.getValue(Config.StorageCacheReplacementLRUTimeInterval.key()), 30); + } + + public void setUnusedTimeInterval(Integer interval) { + unusedTimeInterval = interval; + } + + @Override + public DataObject chooseOneToBeReplaced(DataStore store) { + Calendar cal = Calendar.getInstance(); + cal.setTime(DateUtil.now()); + cal.add(Calendar.DAY_OF_MONTH, -unusedTimeInterval.intValue()); + Date bef = cal.getTime(); + + SearchCriteriaService sc = SearchCriteria2.create(TemplateDataStoreVO.class); + sc.addAnd(sc.getEntity().getLastUpdated(), SearchCriteria.Op.LT, bef); + sc.addAnd(sc.getEntity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready); + sc.addAnd(sc.getEntity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId()); + sc.addAnd(sc.getEntity().getDataStoreRole(), SearchCriteria.Op.EQ, store.getRole()); + sc.addAnd(sc.getEntity().getRefCnt(), SearchCriteria.Op.EQ, 0); + TemplateDataStoreVO template = sc.find(); + if (template != null) { + return templateFactory.getTemplate(template.getTemplateId(), store); + } + + SearchCriteriaService volSc = SearchCriteria2.create(VolumeDataStoreVO.class); + volSc.addAnd(volSc.getEntity().getLastUpdated(), SearchCriteria.Op.LT, bef); + volSc.addAnd(volSc.getEntity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready); + volSc.addAnd(volSc.getEntity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId()); + volSc.addAnd(volSc.getEntity().getRefCnt(), SearchCriteria.Op.EQ, 0); + VolumeDataStoreVO volume = volSc.find(); + if (volume != null) { + return volumeFactory.getVolume(volume.getVolumeId(), store); + } + + SearchCriteriaService snapshotSc = SearchCriteria2.create(SnapshotDataStoreVO.class); + snapshotSc.addAnd(snapshotSc.getEntity().getLastUpdated(), SearchCriteria.Op.LT, bef); + snapshotSc.addAnd(snapshotSc.getEntity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready); + snapshotSc.addAnd(snapshotSc.getEntity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId()); + snapshotSc.addAnd(snapshotSc.getEntity().getRole(), SearchCriteria.Op.EQ, store.getRole()); + snapshotSc.addAnd(snapshotSc.getEntity().getRefCnt(), SearchCriteria.Op.EQ, 0); + SnapshotDataStoreVO snapshot = snapshotSc.find(); + if (snapshot != null) { + return snapshotFactory.getSnapshot(snapshot.getSnapshotId(), store); + } + + return null; + } +} diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java index a01d2d30139..631de6a47a3 100644 --- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java +++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java @@ -172,10 +172,11 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { EndPoint ep = selector.select(srcData, destData); answer = ep.sendMessage(cmd); } - // clean up cache entry in case of failure - if (answer == null || !answer.getResult()) { - if (cacheData != null) { + if (cacheData != null) { + if (answer == null || !answer.getResult()) { cacheMgr.deleteCacheObject(cacheData); + } else { + cacheMgr.releaseCacheObject(cacheData); } } return answer; @@ -191,8 +192,9 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { protected DataObject cacheSnapshotChain(SnapshotInfo snapshot) { DataObject leafData = null; + DataStore store = cacheMgr.getCacheStorage(snapshot.getDataStore().getScope()); while (snapshot != null) { - DataObject cacheData = cacheMgr.createCacheObject(snapshot, snapshot.getDataStore().getScope()); + DataObject cacheData = cacheMgr.createCacheObject(snapshot, store); if (leafData == null) { leafData = cacheData; } @@ -202,7 +204,10 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { } protected void deleteSnapshotCacheChain(SnapshotInfo snapshot) { - + while (snapshot != null) { + cacheMgr.deleteCacheObject(snapshot); + snapshot = snapshot.getParent(); + } } protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) { diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java deleted file mode 100644 index e4141f3fa00..00000000000 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java +++ /dev/null @@ -1,29 +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.image; - -public interface ImageOrchestrator { - void registerTemplate(long templateId); - - void registerSnapshot(long snapshotId); - - void registerVolume(long volumeId); - - void registerIso(long isoId); -} diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java index c06756e4e9c..96c35f36f34 100644 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java +++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java @@ -576,8 +576,6 @@ public class TemplateServiceImpl implements TemplateService { if (result.isFailed()) { res.setResult(result.getResult()); destTemplate.processEvent(Event.OperationFailed); - // remove entry from template_store_ref - destTemplate.getDataStore().delete(destTemplate); } else { destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer()); } diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java deleted file mode 100644 index af572d49a5e..00000000000 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java +++ /dev/null @@ -1,25 +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.image.downloader; - -import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; - -public interface ImageDownloader { - public void downloadImage(TemplateInfo template); -} diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java index 73c960fef9e..64ef78f8e09 100644 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java +++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java @@ -66,7 +66,6 @@ public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager ImageStoreProvider provider = (ImageStoreProvider) providerManager.getDataStoreProvider(providerName); ImageStoreEntity imgStore = ImageStoreImpl .getDataStore(dataStore, driverMaps.get(provider.getName()), provider); - // TODO Auto-generated method stub return imgStore; } diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java index a3da304bccc..6d8e8e59c6f 100644 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java +++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java @@ -24,6 +24,7 @@ import java.util.concurrent.ExecutionException; import javax.inject.Inject; +import com.cloud.capacity.dao.CapacityDao; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; @@ -52,10 +53,11 @@ public class ImageStoreImpl implements ImageStoreEntity { VMTemplateDao imageDao; @Inject private ObjectInDataStoreManager objectInStoreMgr; + @Inject + private CapacityDao capacityDao; protected ImageStoreDriver driver; protected ImageStoreVO imageDataStoreVO; protected ImageStoreProvider provider; - boolean needDownloadToCacheStorage = false; public ImageStoreImpl() { super(); @@ -77,13 +79,11 @@ public class ImageStoreImpl implements ImageStoreEntity { @Override public Set listTemplates() { - // TODO Auto-generated method stub return null; } @Override public DataStoreDriver getDriver() { - // TODO Auto-generated method stub return this.driver; } @@ -94,7 +94,6 @@ public class ImageStoreImpl implements ImageStoreEntity { @Override public long getId() { - // TODO Auto-generated method stub return this.imageDataStoreVO.getId(); } @@ -110,19 +109,16 @@ public class ImageStoreImpl implements ImageStoreEntity { @Override public TemplateInfo getTemplate(long templateId) { - // TODO Auto-generated method stub return null; } @Override public VolumeInfo getVolume(long volumeId) { - // TODO Auto-generated method stub return null; } @Override public SnapshotInfo getSnapshot(long snapshotId) { - // TODO Auto-generated method stub return null; } diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java index 72a8849d05f..5ab52de8500 100644 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java +++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java @@ -258,6 +258,48 @@ public class TemplateObject implements TemplateInfo { } } + @Override + public void incRefCount() { + if (this.dataStore == null) { + return; + } + + if (this.dataStore.getRole() == DataStoreRole.Image || + this.dataStore.getRole() == DataStoreRole.ImageCache) { + TemplateDataStoreVO store = templateStoreDao.findById(this.dataStore.getId()); + store.incrRefCnt(); + store.setLastUpdated(new Date()); + templateStoreDao.update(store.getId(), store); + } + } + + @Override + public void decRefCount() { + if (this.dataStore == null) { + return; + } + if (this.dataStore.getRole() == DataStoreRole.Image || + this.dataStore.getRole() == DataStoreRole.ImageCache) { + TemplateDataStoreVO store = templateStoreDao.findById(this.dataStore.getId()); + store.decrRefCnt(); + store.setLastUpdated(new Date()); + templateStoreDao.update(store.getId(), store); + } + } + + @Override + public Long getRefCount() { + if (this.dataStore == null) { + return null; + } + if (this.dataStore.getRole() == DataStoreRole.Image || + this.dataStore.getRole() == DataStoreRole.ImageCache) { + TemplateDataStoreVO store = templateStoreDao.findById(this.dataStore.getId()); + return store.getRefCnt(); + } + return null; + } + @Override public DataTO getTO() { DataTO to = null; diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/allocator/StorageAllocatorTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/allocator/StorageAllocatorTest.java index 3d300de1060..40d9d418938 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/allocator/StorageAllocatorTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/allocator/StorageAllocatorTest.java @@ -128,7 +128,7 @@ public class StorageAllocatorTest { storage.setClusterId(clusterId); storage.setStatus(StoragePoolStatus.Up); storage.setScope(ScopeType.CLUSTER); - storage.setAvailableBytes(1000); + storage.setUsedBytes(1000); storage.setCapacityBytes(20000); storage.setHostAddress(UUID.randomUUID().toString()); storage.setPath(UUID.randomUUID().toString()); @@ -170,7 +170,7 @@ public class StorageAllocatorTest { storage.setClusterId(clusterId); storage.setStatus(StoragePoolStatus.Up); storage.setScope(ScopeType.CLUSTER); - storage.setAvailableBytes(1000); + storage.setUsedBytes(1000); storage.setCapacityBytes(20000); storage.setHostAddress(UUID.randomUUID().toString()); storage.setPath(UUID.randomUUID().toString()); diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/cache/manager/StorageCacheReplacementAlgorithmLRUTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/cache/manager/StorageCacheReplacementAlgorithmLRUTest.java new file mode 100644 index 00000000000..7d40ea796e1 --- /dev/null +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/cache/manager/StorageCacheReplacementAlgorithmLRUTest.java @@ -0,0 +1,226 @@ +/* + * 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.cache.manager; + +import com.cloud.storage.DataStoreRole; +import com.cloud.storage.Storage; +import com.cloud.storage.VMTemplateVO; +import com.cloud.storage.dao.VMTemplateDao; +import com.cloud.utils.DateUtil; +import com.cloud.utils.component.ComponentContext; +import junit.framework.Assert; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; +import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; +import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; +import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import javax.inject.Inject; +import java.util.Calendar; +import java.util.Date; +import java.util.UUID; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "classpath:/storageContext.xml") +public class StorageCacheReplacementAlgorithmLRUTest { + @Inject + VMTemplateDao templateDao; + @Inject + ImageStoreDao imageStoreDao; + @Inject + TemplateDataStoreDao templateDataStoreDao; + @Inject + StorageCacheReplacementAlgorithmLRU cacheReplacementAlgorithm; + @Inject + DataStoreManager dataStoreManager; + @Before + public void setup() throws Exception { + ComponentContext.initComponentsLifeCycle(); + } + @Test + public void testSelectObject() { + cacheReplacementAlgorithm.setUnusedTimeInterval(1); + try { + VMTemplateVO template = new VMTemplateVO(); + template.setTemplateType(Storage.TemplateType.USER); + template.setUrl(UUID.randomUUID().toString()); + template.setUniqueName(UUID.randomUUID().toString()); + template.setName(UUID.randomUUID().toString()); + template.setPublicTemplate(true); + template.setFeatured(true); + template.setRequiresHvm(true); + template.setBits(64); + template.setFormat(Storage.ImageFormat.VHD); + template.setEnablePassword(true); + template.setEnableSshKey(true); + template.setGuestOSId(1); + template.setBootable(true); + template.setPrepopulate(true); + template.setCrossZones(true); + template.setExtractable(true); + template = templateDao.persist(template); + + VMTemplateVO template2 = new VMTemplateVO(); + template2.setTemplateType(Storage.TemplateType.USER); + template2.setUrl(UUID.randomUUID().toString()); + template2.setUniqueName(UUID.randomUUID().toString()); + template2.setName(UUID.randomUUID().toString()); + template2.setPublicTemplate(true); + template2.setFeatured(true); + template2.setRequiresHvm(true); + template2.setBits(64); + template2.setFormat(Storage.ImageFormat.VHD); + template2.setEnablePassword(true); + template2.setEnableSshKey(true); + template2.setGuestOSId(1); + template2.setBootable(true); + template2.setPrepopulate(true); + template2.setCrossZones(true); + template2.setExtractable(true); + template2 = templateDao.persist(template2); + + ImageStoreVO imageStoreVO = new ImageStoreVO(); + imageStoreVO.setRole(DataStoreRole.ImageCache); + imageStoreVO.setName(UUID.randomUUID().toString()); + imageStoreVO.setProviderName(DataStoreProvider.NFS_IMAGE); + imageStoreVO.setProtocol("nfs"); + imageStoreVO.setUrl(UUID.randomUUID().toString()); + imageStoreVO = imageStoreDao.persist(imageStoreVO); + + Calendar cal = Calendar.getInstance(); + cal.setTime(DateUtil.now()); + cal.add(Calendar.DAY_OF_MONTH, -2); + Date date = cal.getTime(); + + TemplateDataStoreVO templateStoreVO1 = new TemplateDataStoreVO(); + templateStoreVO1.setLastUpdated(date); + templateStoreVO1.setDataStoreRole(DataStoreRole.ImageCache); + templateStoreVO1.setDataStoreId(imageStoreVO.getId()); + templateStoreVO1.setState(ObjectInDataStoreStateMachine.State.Ready); + templateStoreVO1.setCopy(true); + templateStoreVO1.setTemplateId(template.getId()); + templateDataStoreDao.persist(templateStoreVO1); + + TemplateDataStoreVO templateStoreVO2 = new TemplateDataStoreVO(); + templateStoreVO2.setLastUpdated(date); + templateStoreVO2.setDataStoreRole(DataStoreRole.ImageCache); + templateStoreVO2.setDataStoreId(imageStoreVO.getId()); + templateStoreVO2.setState(ObjectInDataStoreStateMachine.State.Ready); + templateStoreVO2.setCopy(true); + templateStoreVO2.setTemplateId(template2.getId()); + templateDataStoreDao.persist(templateStoreVO2); + + DataStore store = dataStoreManager.getDataStore(imageStoreVO.getId(), DataStoreRole.ImageCache); + Assert.assertNotNull(cacheReplacementAlgorithm.chooseOneToBeReplaced(store)); + + } catch (Exception e) { + Assert.fail(); + } + } + + + @Test + public void testSelectObjectFailed() { + cacheReplacementAlgorithm.setUnusedTimeInterval(1); + try { + VMTemplateVO template = new VMTemplateVO(); + template.setTemplateType(Storage.TemplateType.USER); + template.setUrl(UUID.randomUUID().toString()); + template.setUniqueName(UUID.randomUUID().toString()); + template.setName(UUID.randomUUID().toString()); + template.setPublicTemplate(true); + template.setFeatured(true); + template.setRequiresHvm(true); + template.setBits(64); + template.setFormat(Storage.ImageFormat.VHD); + template.setEnablePassword(true); + template.setEnableSshKey(true); + template.setGuestOSId(1); + template.setBootable(true); + template.setPrepopulate(true); + template.setCrossZones(true); + template.setExtractable(true); + template = templateDao.persist(template); + + VMTemplateVO template2 = new VMTemplateVO(); + template2.setTemplateType(Storage.TemplateType.USER); + template2.setUrl(UUID.randomUUID().toString()); + template2.setUniqueName(UUID.randomUUID().toString()); + template2.setName(UUID.randomUUID().toString()); + template2.setPublicTemplate(true); + template2.setFeatured(true); + template2.setRequiresHvm(true); + template2.setBits(64); + template2.setFormat(Storage.ImageFormat.VHD); + template2.setEnablePassword(true); + template2.setEnableSshKey(true); + template2.setGuestOSId(1); + template2.setBootable(true); + template2.setPrepopulate(true); + template2.setCrossZones(true); + template2.setExtractable(true); + template2 = templateDao.persist(template2); + + ImageStoreVO imageStoreVO = new ImageStoreVO(); + imageStoreVO.setRole(DataStoreRole.ImageCache); + imageStoreVO.setName(UUID.randomUUID().toString()); + imageStoreVO.setProviderName(DataStoreProvider.NFS_IMAGE); + imageStoreVO.setProtocol("nfs"); + imageStoreVO.setUrl(UUID.randomUUID().toString()); + imageStoreVO = imageStoreDao.persist(imageStoreVO); + + + Date date = DateUtil.now(); + + TemplateDataStoreVO templateStoreVO1 = new TemplateDataStoreVO(); + templateStoreVO1.setLastUpdated(date); + templateStoreVO1.setDataStoreRole(DataStoreRole.ImageCache); + templateStoreVO1.setDataStoreId(imageStoreVO.getId()); + templateStoreVO1.setState(ObjectInDataStoreStateMachine.State.Ready); + templateStoreVO1.setCopy(true); + templateStoreVO1.setTemplateId(template.getId()); + templateDataStoreDao.persist(templateStoreVO1); + + TemplateDataStoreVO templateStoreVO2 = new TemplateDataStoreVO(); + templateStoreVO2.setLastUpdated(date); + templateStoreVO2.setDataStoreRole(DataStoreRole.ImageCache); + templateStoreVO2.setDataStoreId(imageStoreVO.getId()); + templateStoreVO2.setState(ObjectInDataStoreStateMachine.State.Ready); + templateStoreVO2.setCopy(true); + templateStoreVO2.setTemplateId(template2.getId()); + templateDataStoreDao.persist(templateStoreVO2); + + DataStore store = dataStoreManager.getDataStore(imageStoreVO.getId(), DataStoreRole.ImageCache); + Assert.assertNull(cacheReplacementAlgorithm.chooseOneToBeReplaced(store)); + + } catch (Exception e) { + Assert.fail(); + } + } + + +} diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java index 8210dfe45bd..2579a38157d 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/SnapshotTest.java @@ -26,6 +26,8 @@ import java.util.concurrent.ExecutionException; import javax.inject.Inject; +import junit.framework.Assert; + import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; @@ -43,6 +45,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; +import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult; import org.apache.cloudstack.framework.async.AsyncCallFuture; import org.apache.cloudstack.storage.LocalHostEndpoint; @@ -351,7 +354,7 @@ public class SnapshotTest extends CloudStackTestNGBase { return volume; } - public VolumeInfo createCopyBaseImage() { + public VolumeInfo createCopyBaseImage() throws InterruptedException, ExecutionException { DataStore primaryStore = createPrimaryDataStore(); primaryStoreId = primaryStore.getId(); primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId); @@ -361,45 +364,13 @@ public class SnapshotTest extends CloudStackTestNGBase { this.primaryStoreId, this.templateFactory.getTemplate(this.image.getId(), DataStoreRole.Image)); VolumeApiResult result; - try { - result = future.get(); - return result.getVolume(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; + result = future.get(); + Assert.assertTrue(result.isSuccess()); + return result.getVolume(); + } - @Test - public void createSnapshot() { - VolumeInfo vol = createCopyBaseImage(); - SnapshotVO snapshotVO = createSnapshotInDb(vol); - SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore()); - SnapshotInfo newSnapshot = null; - for (SnapshotStrategy strategy : this.snapshotStrategies) { - if (strategy.canHandle(snapshot)) { - newSnapshot = strategy.takeSnapshot(snapshot); - } - } - AssertJUnit.assertNotNull(newSnapshot); - - LocalHostEndpoint ep = new MockLocalHostEndPoint(); - ep.setResource(new MockLocalNfsSecondaryStorageResource()); - Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep); - - // delete snapshot - for (SnapshotStrategy strategy : this.snapshotStrategies) { - if (strategy.canHandle(snapshot)) { - strategy.deleteSnapshot(newSnapshot.getId()); - } - } - - Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(remoteEp); - } + private VMTemplateVO createTemplateInDb() { VMTemplateVO image = new VMTemplateVO(); @@ -424,7 +395,7 @@ public class SnapshotTest extends CloudStackTestNGBase { } @Test - public void createVolumeFromSnapshot() { + public void createVolumeFromSnapshot() throws InterruptedException, ExecutionException { VolumeInfo vol = createCopyBaseImage(); SnapshotVO snapshotVO = createSnapshotInDb(vol); SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore()); @@ -440,11 +411,13 @@ public class SnapshotTest extends CloudStackTestNGBase { VolumeVO volVO = createVolume(vol.getTemplateId(), vol.getPoolId()); VolumeInfo newVol = this.volFactory.getVolume(volVO.getId()); - this.volumeService.createVolumeFromSnapshot(newVol, newVol.getDataStore(), snapshot); + AsyncCallFuture volFuture = this.volumeService.createVolumeFromSnapshot(newVol, newVol.getDataStore(), snapshot); + VolumeApiResult apiResult = volFuture.get(); + Assert.assertTrue(apiResult.isSuccess()); } @Test - public void deleteSnapshot() { + public void deleteSnapshot() throws InterruptedException, ExecutionException { VolumeInfo vol = createCopyBaseImage(); SnapshotVO snapshotVO = createSnapshotInDb(vol); SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore()); @@ -466,7 +439,7 @@ public class SnapshotTest extends CloudStackTestNGBase { } @Test - public void createTemplateFromSnapshot() { + public void createTemplateFromSnapshot() throws InterruptedException, ExecutionException { VolumeInfo vol = createCopyBaseImage(); SnapshotVO snapshotVO = createSnapshotInDb(vol); SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore()); @@ -482,10 +455,46 @@ public class SnapshotTest extends CloudStackTestNGBase { LocalHostEndpoint ep = new LocalHostEndpoint(); ep.setResource(new MockLocalNfsSecondaryStorageResource()); Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep); - VMTemplateVO templateVO = createTemplateInDb(); - TemplateInfo tmpl = this.templateFactory.getTemplate(templateVO.getId(), DataStoreRole.Image); - DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId); - this.imageService.createTemplateFromSnapshotAsync(snapshot, tmpl, imageStore); + + try { + VMTemplateVO templateVO = createTemplateInDb(); + TemplateInfo tmpl = this.templateFactory.getTemplate(templateVO.getId(), DataStoreRole.Image); + DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId); + AsyncCallFuture templateFuture = this.imageService.createTemplateFromSnapshotAsync(snapshot, tmpl, imageStore); + TemplateApiResult apiResult = templateFuture.get(); + Assert.assertTrue(apiResult.isSuccess()); + } finally { + Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(remoteEp); + } + } + + @Test + public void createSnapshot() throws InterruptedException, ExecutionException { + VolumeInfo vol = createCopyBaseImage(); + SnapshotVO snapshotVO = createSnapshotInDb(vol); + SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore()); + SnapshotInfo newSnapshot = null; + for (SnapshotStrategy strategy : this.snapshotStrategies) { + if (strategy.canHandle(snapshot)) { + newSnapshot = strategy.takeSnapshot(snapshot); + } + } + AssertJUnit.assertNotNull(newSnapshot); + + LocalHostEndpoint ep = new MockLocalHostEndPoint(); + ep.setResource(new MockLocalNfsSecondaryStorageResource()); + Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep); + + try { + for (SnapshotStrategy strategy : this.snapshotStrategies) { + if (strategy.canHandle(snapshot)) { + boolean res = strategy.deleteSnapshot(newSnapshot.getId()); + Assert.assertTrue(res); + } + } + } finally { + Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(remoteEp); + } } } diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java index ef5c4caae96..70fdb1b5829 100644 --- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java +++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java @@ -26,6 +26,8 @@ import java.util.concurrent.ExecutionException; import javax.inject.Inject; +import junit.framework.Assert; + import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; @@ -39,6 +41,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; +import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult; import org.apache.cloudstack.framework.async.AsyncCallFuture; import org.apache.cloudstack.storage.RemoteHostEndPoint; @@ -237,6 +240,7 @@ public class VolumeTest extends CloudStackTestNGBase { TemplateObjectTO to = new TemplateObjectTO(); to.setPath(this.getImageInstallPath()); to.setFormat(ImageFormat.VHD); + to.setSize(100L); CopyCmdAnswer answer = new CopyCmdAnswer(to); templateOnStore.processEvent(Event.CreateOnlyRequested); templateOnStore.processEvent(Event.OperationSuccessed, answer); @@ -335,57 +339,52 @@ public class VolumeTest extends CloudStackTestNGBase { AssertJUnit.assertTrue(result.isSuccess()); VolumeInfo newVol = result.getVolume(); - this.volumeService.destroyVolume(newVol.getId()); + boolean res = this.volumeService.destroyVolume(newVol.getId()); + Assert.assertTrue(res); VolumeInfo vol = this.volFactory.getVolume(volume.getId()); - this.volumeService.expungeVolumeAsync(vol); + future = this.volumeService.expungeVolumeAsync(vol); + result = future.get(); + Assert.assertTrue(result.isSuccess()); } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Assert.fail(e.toString()); } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Assert.fail(e.toString()); } catch (ConcurrentOperationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Assert.fail(e.toString()); } } @Test - public void testCreateDataDisk() { - DataStore primaryStore = createPrimaryDataStore(); - primaryStoreId = primaryStore.getId(); - primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId); - VolumeVO volume = createVolume(null, primaryStore.getId()); - VolumeInfo volInfo = this.volFactory.getVolume(volume.getId()); - this.volumeService.createVolumeAsync(volInfo, primaryStore); - } - - @Test - public void testDeleteDisk() { + public void testCreateDataDisk() throws InterruptedException, ExecutionException { DataStore primaryStore = createPrimaryDataStore(); primaryStoreId = primaryStore.getId(); primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId); VolumeVO volume = createVolume(null, primaryStore.getId()); VolumeInfo volInfo = this.volFactory.getVolume(volume.getId()); AsyncCallFuture future = this.volumeService.createVolumeAsync(volInfo, primaryStore); - try { - VolumeApiResult result = future.get(); - VolumeInfo vol = result.getVolume(); + VolumeApiResult result = future.get(); + Assert.assertTrue(result.isSuccess()); + } - this.volumeService.destroyVolume(volInfo.getId()); - volInfo = this.volFactory.getVolume(vol.getId()); - this.volumeService.expungeVolumeAsync(volInfo); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ConcurrentOperationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Test + public void testDeleteDisk() throws InterruptedException, ExecutionException, ConcurrentOperationException { + DataStore primaryStore = createPrimaryDataStore(); + primaryStoreId = primaryStore.getId(); + primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId); + VolumeVO volume = createVolume(null, primaryStore.getId()); + VolumeInfo volInfo = this.volFactory.getVolume(volume.getId()); + AsyncCallFuture future = this.volumeService.createVolumeAsync(volInfo, primaryStore); + VolumeApiResult result = future.get(); + Assert.assertTrue(result.isSuccess()); + VolumeInfo vol = result.getVolume(); + + boolean res = this.volumeService.destroyVolume(volInfo.getId()); + Assert.assertTrue(res); + volInfo = this.volFactory.getVolume(vol.getId()); + future = this.volumeService.expungeVolumeAsync(volInfo); + result = future.get(); + Assert.assertTrue(result.isSuccess()); } private VMTemplateVO createTemplateInDb() { @@ -411,30 +410,24 @@ public class VolumeTest extends CloudStackTestNGBase { } @Test - public void testCreateTemplateFromVolume() { + public void testCreateTemplateFromVolume() throws InterruptedException, ExecutionException { DataStore primaryStore = createPrimaryDataStore(); primaryStoreId = primaryStore.getId(); primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId); VolumeVO volume = createVolume(null, primaryStore.getId()); VolumeInfo volInfo = this.volFactory.getVolume(volume.getId()); AsyncCallFuture future = this.volumeService.createVolumeAsync(volInfo, primaryStore); - try { - VolumeApiResult result = future.get(); - AssertJUnit.assertTrue(result.isSuccess()); - volInfo = result.getVolume(); - VMTemplateVO templateVO = createTemplateInDb(); - TemplateInfo tmpl = this.templateFactory.getTemplate(templateVO.getId(), DataStoreRole.Image); - DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId); + VolumeApiResult result = future.get(); - this.imageService.createTemplateFromVolumeAsync(volInfo, tmpl, imageStore); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + AssertJUnit.assertTrue(result.isSuccess()); + volInfo = result.getVolume(); + VMTemplateVO templateVO = createTemplateInDb(); + TemplateInfo tmpl = this.templateFactory.getTemplate(templateVO.getId(), DataStoreRole.Image); + DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId); + AsyncCallFuture templateResult = this.imageService.createTemplateFromVolumeAsync(volInfo, tmpl, imageStore); + TemplateApiResult templateApiResult = templateResult.get(); + Assert.assertTrue(templateApiResult.isSuccess()); } } diff --git a/engine/storage/integration-test/test/resource/storageContext.xml b/engine/storage/integration-test/test/resource/storageContext.xml index cc8e3bf9294..9f4f102edec 100644 --- a/engine/storage/integration-test/test/resource/storageContext.xml +++ b/engine/storage/integration-test/test/resource/storageContext.xml @@ -43,9 +43,7 @@ - - @@ -76,7 +74,6 @@ - @@ -88,4 +85,6 @@ + + diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java index bd145733afc..03104882706 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java @@ -22,6 +22,7 @@ import java.util.Date; import javax.inject.Inject; +import com.cloud.storage.DataStoreRole; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; @@ -273,6 +274,47 @@ public class SnapshotObject implements SnapshotInfo { this.processEvent(event); } + public void incRefCount() { + if (this.store == null) { + return; + } + + if (this.store.getRole() == DataStoreRole.Image || + this.store.getRole() == DataStoreRole.ImageCache) { + SnapshotDataStoreVO store = snapshotStoreDao.findById(this.store.getId()); + store.incrRefCnt(); + store.setLastUpdated(new Date()); + snapshotStoreDao.update(store.getId(), store); + } + } + + @Override + public void decRefCount() { + if (this.store == null) { + return; + } + if (this.store.getRole() == DataStoreRole.Image || + this.store.getRole() == DataStoreRole.ImageCache) { + SnapshotDataStoreVO store = snapshotStoreDao.findById(this.store.getId()); + store.decrRefCnt(); + store.setLastUpdated(new Date()); + snapshotStoreDao.update(store.getId(), store); + } + } + + @Override + public Long getRefCount() { + if (this.store == null) { + return null; + } + if (this.store.getRole() == DataStoreRole.Image || + this.store.getRole() == DataStoreRole.ImageCache) { + SnapshotDataStoreVO store = snapshotStoreDao.findById(this.store.getId()); + return store.getRefCnt(); + } + return null; + } + @Override public ObjectInDataStoreStateMachine.State getStatus() { return this.objectInStoreMgr.findObject(this, store).getObjectInStoreState(); @@ -280,8 +322,6 @@ public class SnapshotObject implements SnapshotInfo { @Override public void addPayload(Object data) { - // TODO Auto-generated method stub - } @Override diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java index ed538114177..631d220f69d 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java @@ -17,23 +17,19 @@ package org.apache.cloudstack.storage.snapshot; -import java.util.concurrent.ExecutionException; - -import javax.inject.Inject; - -import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; -import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult; -import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; -import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; +import com.cloud.dc.dao.ClusterDao; +import com.cloud.storage.DataStoreRole; +import com.cloud.storage.Snapshot; +import com.cloud.storage.VolumeManager; +import com.cloud.storage.dao.SnapshotDao; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.storage.snapshot.SnapshotManager; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.fsm.NoTransitionException; +import com.cloud.vm.dao.UserVmDao; +import com.cloud.vm.snapshot.dao.VMSnapshotDao; +import org.apache.cloudstack.engine.subsystem.api.storage.*; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; -import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult; -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService; -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.framework.async.AsyncCallFuture; import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; @@ -47,19 +43,8 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; -import com.cloud.dc.dao.ClusterDao; -import com.cloud.storage.DataStoreRole; -import com.cloud.storage.Snapshot; -import com.cloud.storage.SnapshotVO; -import com.cloud.storage.VolumeManager; -import com.cloud.storage.dao.SnapshotDao; -import com.cloud.storage.dao.VolumeDao; -import com.cloud.storage.snapshot.SnapshotManager; -import com.cloud.utils.db.DB; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.fsm.NoTransitionException; -import com.cloud.vm.dao.UserVmDao; -import com.cloud.vm.snapshot.dao.VMSnapshotDao; +import javax.inject.Inject; +import java.util.concurrent.ExecutionException; @Component public class SnapshotServiceImpl implements SnapshotService { @@ -391,7 +376,6 @@ public class SnapshotServiceImpl implements SnapshotService { @Override public boolean revertSnapshot(SnapshotInfo snapshot) { - // TODO Auto-generated method stub return false; } diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotStateMachineManager.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotStateMachineManager.java index f07db7ed9a0..2ad4ae7d073 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotStateMachineManager.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotStateMachineManager.java @@ -22,5 +22,5 @@ import com.cloud.storage.SnapshotVO; import com.cloud.utils.fsm.NoTransitionException; public interface SnapshotStateMachineManager { - public void processEvent(SnapshotVO snapshot, Event event) throws NoTransitionException; + void processEvent(SnapshotVO snapshot, Event event) throws NoTransitionException; } diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java index 0c3f31c9ef8..92af8c2b071 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java @@ -194,7 +194,6 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase { @Override public SnapshotInfo takeSnapshot(SnapshotInfo snapshot) { snapshot = snapshotSvr.takeSnapshot(snapshot).getSnashot(); - // TODO: add async return this.backupSnapshot(snapshot); } diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2.java deleted file mode 100644 index d531ede0aba..00000000000 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2.java +++ /dev/null @@ -1,25 +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.snapshot.db; - -import com.cloud.utils.db.GenericDao; - -public interface SnapshotDao2 extends GenericDao { - -} diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2Impl.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2Impl.java deleted file mode 100644 index 74cec5e76e5..00000000000 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2Impl.java +++ /dev/null @@ -1,28 +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.snapshot.db; - -import org.springframework.stereotype.Component; - -import com.cloud.utils.db.GenericDaoBase; - -@Component -public class SnapshotDao2Impl extends GenericDaoBase implements SnapshotDao2 { - -} diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotVO.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotVO.java deleted file mode 100644 index 43ec6097cac..00000000000 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotVO.java +++ /dev/null @@ -1,296 +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.snapshot.db; - -import java.util.Date; -import java.util.UUID; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.storage.Snapshot.State; -import com.cloud.storage.Snapshot.Type; -import com.cloud.utils.db.GenericDao; -import com.google.gson.annotations.Expose; - -@Entity -@Table(name = "snapshots") -public class SnapshotVO { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private final long id = -1; - - @Column(name = "data_center_id") - long dataCenterId; - - @Column(name = "account_id") - long accountId; - - @Column(name = "domain_id") - long domainId; - - @Column(name = "volume_id") - Long volumeId; - - @Column(name = "disk_offering_id") - Long diskOfferingId; - - @Expose - @Column(name = "path") - String path; - - @Expose - @Column(name = "name") - String name; - - @Expose - @Column(name = "status", updatable = true, nullable = false) - @Enumerated(value = EnumType.STRING) - private State status; - - @Column(name = "snapshot_type") - short snapshotType; - - @Column(name = "type_description") - String typeDescription; - - @Column(name = "size") - long size; - - @Column(name = GenericDao.CREATED_COLUMN) - Date created; - - @Column(name = GenericDao.REMOVED_COLUMN) - Date removed; - - @Column(name = "backup_snap_id") - String backupSnapshotId; - - @Column(name = "swift_id") - Long swiftId; - - @Column(name = "s3_id") - Long s3Id; - - @Column(name = "sechost_id") - Long secHostId; - - @Column(name = "prev_snap_id") - long prevSnapshotId; - - @Column(name = "hypervisor_type") - @Enumerated(value = EnumType.STRING) - HypervisorType hypervisorType; - - @Expose - @Column(name = "version") - String version; - - @Column(name = "uuid") - String uuid; - - public SnapshotVO() { - this.uuid = UUID.randomUUID().toString(); - } - - public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, Long diskOfferingId, String path, - String name, short snapshotType, String typeDescription, long size, HypervisorType hypervisorType) { - this.dataCenterId = dcId; - this.accountId = accountId; - this.domainId = domainId; - this.volumeId = volumeId; - this.diskOfferingId = diskOfferingId; - this.path = path; - this.name = name; - this.snapshotType = snapshotType; - this.typeDescription = typeDescription; - this.size = size; - this.status = State.Creating; - this.prevSnapshotId = 0; - this.hypervisorType = hypervisorType; - this.version = "2.2"; - this.uuid = UUID.randomUUID().toString(); - } - - public long getId() { - return id; - } - - public long getDataCenterId() { - return dataCenterId; - } - - public long getAccountId() { - return accountId; - } - - public long getDomainId() { - return domainId; - } - - public long getVolumeId() { - return volumeId; - } - - public long getDiskOfferingId() { - return diskOfferingId; - } - - public void setVolumeId(Long volumeId) { - this.volumeId = volumeId; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public String getName() { - return name; - } - - public short getsnapshotType() { - return snapshotType; - } - - public Type getType() { - if (snapshotType < 0 || snapshotType >= Type.values().length) { - return null; - } - return Type.values()[snapshotType]; - } - - public Long getSwiftId() { - return swiftId; - } - - public void setSwiftId(Long swiftId) { - this.swiftId = swiftId; - } - - public Long getSecHostId() { - return secHostId; - } - - public void setSecHostId(Long secHostId) { - this.secHostId = secHostId; - } - - public HypervisorType getHypervisorType() { - return hypervisorType; - } - - public void setSnapshotType(short snapshotType) { - this.snapshotType = snapshotType; - } - - public boolean isRecursive() { - if (snapshotType >= Type.HOURLY.ordinal() && snapshotType <= Type.MONTHLY.ordinal()) { - return true; - } - return false; - } - - public long getSize() { - return size; - } - - public String getTypeDescription() { - return typeDescription; - } - - public void setTypeDescription(String typeDescription) { - this.typeDescription = typeDescription; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public Date getCreated() { - return created; - } - - public Date getRemoved() { - return removed; - } - - public State getStatus() { - return status; - } - - public void setStatus(State status) { - this.status = status; - } - - public String getBackupSnapshotId() { - return backupSnapshotId; - } - - public long getPrevSnapshotId() { - return prevSnapshotId; - } - - public void setBackupSnapshotId(String backUpSnapshotId) { - this.backupSnapshotId = backUpSnapshotId; - } - - public void setPrevSnapshotId(long prevSnapshotId) { - this.prevSnapshotId = prevSnapshotId; - } - - public static Type getSnapshotType(String snapshotType) { - for (Type type : Type.values()) { - if (type.equals(snapshotType)) { - return type; - } - } - return null; - } - - public String getUuid() { - return this.uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public Long getS3Id() { - return s3Id; - } - - public void setS3Id(Long s3Id) { - this.s3Id = s3Id; - } - -} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java index 7120da175d0..b92f92f655e 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java @@ -54,11 +54,6 @@ public class DataStoreManagerImpl implements DataStoreManager { throw new CloudRuntimeException("un recognized type" + role); } - @Override - public DataStore registerDataStore(Map params, String providerUuid) { - return null; - } - @Override public DataStore getDataStore(String uuid, DataStoreRole role) { if (role == DataStoreRole.Primary) { @@ -84,11 +79,6 @@ public class DataStoreManagerImpl implements DataStoreManager { return stores.get(0); } - @Override - public List getImageStoresByProvider(String provider) { - return imageDataStoreMgr.listImageStoreByProvider(provider); - } - @Override public DataStore getPrimaryDataStore(long storeId) { return primaryStorMgr.getPrimaryDataStore(storeId); diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreEntityImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreEntityImpl.java index f62adfce999..e861910116a 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreEntityImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreEntityImpl.java @@ -170,7 +170,7 @@ public class PrimaryDataStoreEntityImpl implements StorageEntity { } @Override - public long getAvailableBytes() { + public long getUsedBytes() { // TODO Auto-generated method stub return 0; } diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java index db056e9e4c0..50238a89a70 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java @@ -57,12 +57,6 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto return providerMap.get(name); } - @Override - public List getDataStoreProviders() { - // TODO Auto-generated method stub - return null; - } - public List getPrimaryDataStoreProviders() { List providers = new ArrayList(); for (DataStoreProvider provider : providerMap.values()) { 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 561c8c446b3..93b0c2b373d 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java @@ -66,30 +66,11 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { @Inject EndPointSelector _epSelector; - @Override - public String grantAccess(DataObject data, EndPoint ep) { - // TODO Auto-generated method stub - return null; - } - @Override public DataTO getTO(DataObject data) { return null; } - - @Override - public boolean revokeAccess(DataObject data, EndPoint ep) { - // TODO Auto-generated method stub - return false; - } - - @Override - public Set listObjects(DataStore store) { - // TODO Auto-generated method stub - return null; - } - class CreateContext extends AsyncRpcConext { final DataObject data; @@ -202,8 +183,6 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { return null; } - - @Override public void deleteAsync(DataObject data, AsyncCompletionCallback callback) { DeleteCommand cmd = new DeleteCommand(data.getTO()); @@ -224,21 +203,14 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { @Override public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public boolean canCopy(DataObject srcData, DataObject destData) { - // TODO Auto-generated method stub return false; } @Override public void resize(DataObject data, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } - - } diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java b/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java index 70e5a5a7b23..6815dec4d99 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java @@ -108,12 +108,12 @@ public class PrimaryDataStoreHelper { StoragePoolVO pool = this.dataStoreDao.findById(store.getId()); pool.setScope(scope.getScopeType()); - pool.setAvailableBytes(existingInfo.getAvailableBytes()); + pool.setUsedBytes(existingInfo.getAvailableBytes()); pool.setCapacityBytes(existingInfo.getCapacityBytes()); pool.setStatus(StoragePoolStatus.Up); this.dataStoreDao.update(pool.getId(), pool); this.storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, - pool.getCapacityBytes() - pool.getAvailableBytes()); + pool.getUsedBytes()); return dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); } diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java index 1fc82510b50..cfdb5c0821d 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java @@ -168,19 +168,16 @@ public class PrimaryDataStoreImpl implements PrimaryDataStore { @Override public boolean isHypervisorSupported(HypervisorType hypervisor) { - // TODO Auto-generated method stub return true; } @Override public boolean isLocalStorageSupported() { - // TODO Auto-generated method stub return false; } @Override public boolean isVolumeDiskTypeSupported(DiskFormat diskType) { - // TODO Auto-generated method stub return false; } @@ -216,13 +213,11 @@ public class PrimaryDataStoreImpl implements PrimaryDataStore { @Override public SnapshotInfo getSnapshot(long snapshotId) { - // TODO Auto-generated method stub return null; } @Override public DiskFormat getDefaultDiskType() { - // TODO Auto-generated method stub return null; } @@ -288,8 +283,8 @@ public class PrimaryDataStoreImpl implements PrimaryDataStore { } @Override - public long getAvailableBytes() { - return this.pdsv.getAvailableBytes(); + public long getUsedBytes() { + return this.pdsv.getUsedBytes(); } @Override diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java deleted file mode 100644 index b248758bc12..00000000000 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java +++ /dev/null @@ -1,16 +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. diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java index 6431308ff74..fa5e2167cc8 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java @@ -81,7 +81,7 @@ public class DefaultHostListener implements HypervisorHostListener { } StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId); - poolVO.setAvailableBytes(mspAnswer.getPoolInfo().getAvailableBytes()); + poolVO.setUsedBytes(mspAnswer.getPoolInfo().getAvailableBytes()); poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes()); primaryStoreDao.update(pool.getId(), poolVO); diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeEntityImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeEntityImpl.java deleted file mode 100644 index 454a50c38bf..00000000000 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeEntityImpl.java +++ /dev/null @@ -1,201 +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.volume; - -import java.lang.reflect.Method; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.apache.cloudstack.engine.cloud.entity.api.SnapshotEntity; -import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; -import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity; -import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo; -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult; -import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat; -import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType; -import org.apache.cloudstack.storage.datastore.PrimaryDataStoreEntityImpl; - -public class VolumeEntityImpl implements VolumeEntity { - private VolumeInfo volumeInfo; - private final VolumeService vs; - private VolumeApiResult result; - - public VolumeEntityImpl() { - this.vs = null; - } - - public VolumeEntityImpl(VolumeInfo volumeObject, VolumeService vs) { - this.volumeInfo = volumeObject; - this.vs = vs; - } - - public VolumeInfo getVolumeInfo() { - return volumeInfo; - } - - @Override - public String getUuid() { - return volumeInfo.getUuid(); - } - - @Override - public long getId() { - return volumeInfo.getId(); - } - - public String getExternalId() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getCurrentState() { - return null; - } - - @Override - public String getDesiredState() { - return null; - } - - @Override - public Date getCreatedTime() { - return null; - } - - @Override - public Date getLastUpdatedTime() { - return null; - } - - @Override - public String getOwner() { - return null; - } - - @Override - public List getApplicableActions() { - // TODO Auto-generated method stub - return null; - } - - @Override - public SnapshotEntity takeSnapshotOf(boolean full) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String reserveForMigration(long expirationTime) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void migrate(String reservationToken) { - // TODO Auto-generated method stub - - } - - @Override - public VolumeEntity setupForCopy() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void copy(VolumeEntity dest) { - // TODO Auto-generated method stub - - } - - @Override - public void attachTo(String vm, long deviceId) { - // TODO Auto-generated method stub - - } - - @Override - public void detachFrom() { - // TODO Auto-generated method stub - - } - - @Override - public long getSize() { - return volumeInfo.getSize(); - } - - @Override - public DiskFormat getDiskType() { - return null; - } - - @Override - public VolumeType getType() { - return null; - } - - @Override - public StorageEntity getDataStore() { - return new PrimaryDataStoreEntityImpl((PrimaryDataStoreInfo) volumeInfo.getDataStore()); - } - - @Override - public void destroy() { - /* - * AsyncCallFuture future = - * vs.deleteVolumeAsync(volumeInfo); try { result = future.get(); if - * (!result.isSuccess()) { throw new - * CloudRuntimeException("Failed to create volume:" + - * result.getResult()); } } catch (InterruptedException e) { throw new - * CloudRuntimeException("wait to delete volume info failed", e); } - * catch (ExecutionException e) { throw new - * CloudRuntimeException("wait to delete volume failed", e); } - */ - } - - @Override - public Map getDetails() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void addDetail(String name, String value) { - // TODO Auto-generated method stub - - } - - @Override - public void delDetail(String name, String value) { - // TODO Auto-generated method stub - - } - - @Override - public void updateDetail(String name, String value) { - // TODO Auto-generated method stub - - } - -} diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java index 963015c7945..e799098bbb4 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java @@ -451,6 +451,47 @@ public class VolumeObject implements VolumeInfo { } + public void incRefCount() { + if (this.dataStore == null) { + return; + } + + if (this.dataStore.getRole() == DataStoreRole.Image || + this.dataStore.getRole() == DataStoreRole.ImageCache) { + VolumeDataStoreVO store = volumeStoreDao.findById(this.dataStore.getId()); + store.incrRefCnt(); + store.setLastUpdated(new Date()); + volumeStoreDao.update(store.getId(), store); + } + } + + @Override + public void decRefCount() { + if (this.dataStore == null) { + return; + } + if (this.dataStore.getRole() == DataStoreRole.Image || + this.dataStore.getRole() == DataStoreRole.ImageCache) { + VolumeDataStoreVO store = volumeStoreDao.findById(this.dataStore.getId()); + store.decrRefCnt(); + store.setLastUpdated(new Date()); + volumeStoreDao.update(store.getId(), store); + } + } + + @Override + public Long getRefCount() { + if (this.dataStore == null) { + return null; + } + if (this.dataStore.getRole() == DataStoreRole.Image || + this.dataStore.getRole() == DataStoreRole.ImageCache) { + VolumeDataStoreVO store = volumeStoreDao.findById(this.dataStore.getId()); + return store.getRefCnt(); + } + return null; + } + @Override public void processEventOnly(ObjectInDataStoreStateMachine.Event event, Answer answer) { try { diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 7d5b7a2937c..1d36f938fdf 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -120,9 +120,6 @@ public class VolumeServiceImpl implements VolumeService { private final DataObject volume; private final AsyncCallFuture future; - /** - * @param callback - */ public CreateVolumeContext(AsyncCompletionCallback callback, DataObject volume, AsyncCallFuture future) { super(callback); @@ -178,9 +175,6 @@ public class VolumeServiceImpl implements VolumeService { private final VolumeObject volume; private final AsyncCallFuture future; - /** - * @param callback - */ public DeleteVolumeContext(AsyncCompletionCallback callback, VolumeObject volume, AsyncCallFuture future) { super(callback); @@ -266,17 +260,7 @@ public class VolumeServiceImpl implements VolumeService { @Override public VolumeEntity getVolumeEntity(long volumeId) { - VolumeVO vo = volDao.findById(volumeId); - if (vo == null) { - return null; - } - - if (vo.getPoolId() == null) { - return new VolumeEntityImpl(VolumeObject.getVolumeObject(null, vo), this); - } else { - PrimaryDataStore dataStore = dataStoreMgr.getPrimaryDataStore(vo.getPoolId()); - return new VolumeEntityImpl(dataStore.getVolume(volumeId), this); - } + return null; } class CreateBaseImageContext extends AsyncRpcConext { @@ -315,15 +299,6 @@ public class VolumeServiceImpl implements VolumeService { } - static class CreateBaseImageResult extends CommandResult { - final TemplateInfo template; - - public CreateBaseImageResult(TemplateInfo template) { - super(); - this.template = template; - } - } - private TemplateInfo waitForTemplateDownloaded(PrimaryDataStore store, TemplateInfo template) { int storagePoolMaxWaitSeconds = NumbersUtil.parseInt( configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); @@ -571,9 +546,6 @@ public class VolumeServiceImpl implements VolumeService { final VolumeInfo destVolume; final AsyncCallFuture future; - /** - * @param callback - */ public CopyVolumeContext(AsyncCompletionCallback callback, AsyncCallFuture future, VolumeInfo srcVolume, VolumeInfo destVolume, DataStore destStore) { super(callback); @@ -845,9 +817,6 @@ public class VolumeServiceImpl implements VolumeService { final Map volumeToPool; final AsyncCallFuture future; - /** - * @param callback - */ public MigrateVmWithVolumesContext(AsyncCompletionCallback callback, AsyncCallFuture future, Map volumeToPool) { super(callback); diff --git a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java index 7ff56f6582a..7b30575c8d1 100644 --- a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java +++ b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java @@ -124,50 +124,32 @@ public class CloudStackImageStoreLifeCycleImpl implements ImageStoreLifeCycle { @Override public boolean attachCluster(DataStore store, ClusterScope scope) { - // TODO Auto-generated method stub return false; } @Override public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { - // TODO Auto-generated method stub return false; } @Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean dettach() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean unmanaged() { - // TODO Auto-generated method stub return false; } @Override public boolean maintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean cancelMaintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean deleteDataStore(DataStore store) { - // TODO Auto-generated method stub return false; } } diff --git a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java index 6965a152041..2630d137863 100644 --- a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java +++ b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java @@ -53,8 +53,6 @@ public class S3ImageStoreLifeCycleImpl implements ImageStoreLifeCycle { ImageStoreHelper imageStoreHelper; @Inject ImageStoreProviderManager imageStoreMgr; - @Inject - S3Manager _s3Mgr; protected List _discoverers; @@ -83,12 +81,6 @@ public class S3ImageStoreLifeCycleImpl implements ImageStoreLifeCycle { s_logger.info("Trying to add a S3 store in data center " + dcId); - /* - * try{ // verify S3 parameters _s3Mgr.verifyS3Fields(details); } catch - * (DiscoveryException ex){ throw new - * InvalidParameterValueException("failed to verify S3 parameters!"); } - */ - Map imageStoreParameters = new HashMap(); imageStoreParameters.put("name", name); imageStoreParameters.put("zoneId", dcId); @@ -113,51 +105,31 @@ public class S3ImageStoreLifeCycleImpl implements ImageStoreLifeCycle { @Override public boolean attachCluster(DataStore store, ClusterScope scope) { - // TODO Auto-generated method stub return false; } @Override public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { - // TODO Auto-generated method stub return false; } - - @Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean dettach() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean unmanaged() { - // TODO Auto-generated method stub return false; } @Override public boolean maintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean cancelMaintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean deleteDataStore(DataStore store) { - // TODO Auto-generated method stub return false; } } diff --git a/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/driver/SampleImageStoreDriverImpl.java b/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/driver/SampleImageStoreDriverImpl.java index 2dae3c84bc5..44f94f39ee4 100644 --- a/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/driver/SampleImageStoreDriverImpl.java +++ b/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/driver/SampleImageStoreDriverImpl.java @@ -37,15 +37,12 @@ public class SampleImageStoreDriverImpl extends BaseImageStoreDriverImpl { public SampleImageStoreDriverImpl() { } - @Override public DataStoreTO getStoreTO(DataStore store) { // TODO Auto-generated method stub return null; } - - @Override public String createEntityExtractUrl(DataStore store, String installPath, ImageFormat format) { // TODO Auto-generated method stub diff --git a/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SampleImageStoreLifeCycleImpl.java b/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SampleImageStoreLifeCycleImpl.java index c7e48018eaf..e4df6f55f3a 100644 --- a/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SampleImageStoreLifeCycleImpl.java +++ b/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SampleImageStoreLifeCycleImpl.java @@ -52,49 +52,31 @@ public class SampleImageStoreLifeCycleImpl implements ImageStoreLifeCycle { @Override public boolean attachCluster(DataStore store, ClusterScope scope) { - // TODO Auto-generated method stub return false; } @Override public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { - // TODO Auto-generated method stub return false; } @Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisor) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean dettach() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean unmanaged() { - // TODO Auto-generated method stub return false; } @Override public boolean maintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean cancelMaintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean deleteDataStore(DataStore store) { - // TODO Auto-generated method stub return false; } } diff --git a/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/provider/SampleImageStoreProviderImpl.java b/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/provider/SampleImageStoreProviderImpl.java index c0c55d667d1..c52e96e0c93 100644 --- a/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/provider/SampleImageStoreProviderImpl.java +++ b/plugins/storage/image/sample/src/org/apache/cloudstack/storage/datastore/provider/SampleImageStoreProviderImpl.java @@ -44,8 +44,6 @@ public class SampleImageStoreProviderImpl implements ImageStoreProvider { protected ImageStoreDriver driver; @Inject ImageStoreProviderManager storeMgr; - long id; - String uuid; @Override public DataStoreLifeCycle getDataStoreLifeCycle() { 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 bd5a14a277a..d6d6cd283f1 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 @@ -39,7 +39,6 @@ public class SwiftImageStoreDriverImpl extends BaseImageStoreDriverImpl { @Inject ImageStoreDetailsDao _imageStoreDetailsDao; - @Override public DataStoreTO getStoreTO(DataStore store) { ImageStoreImpl imgStore = (ImageStoreImpl) store; @@ -48,11 +47,9 @@ public class SwiftImageStoreDriverImpl extends BaseImageStoreDriverImpl { details.get(ApiConstants.USERNAME), details.get(ApiConstants.KEY)); } - @Override public String createEntityExtractUrl(DataStore store, String installPath, ImageFormat format) { throw new UnsupportedServiceException("Extract entity url is not yet supported for Swift image store provider"); } - } diff --git a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java index 38e20073491..4256cc2cc7b 100644 --- a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java +++ b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java @@ -16,12 +16,11 @@ // under the License. package org.apache.cloudstack.storage.datastore.lifecycle; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.inject.Inject; - +import com.cloud.agent.api.StoragePoolInfo; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.resource.ResourceManager; +import com.cloud.storage.DataStoreRole; +import com.cloud.storage.ScopeType; 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; @@ -33,12 +32,9 @@ import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle; import org.apache.log4j.Logger; -import com.cloud.agent.api.StoragePoolInfo; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.resource.Discoverer; -import com.cloud.resource.ResourceManager; -import com.cloud.storage.DataStoreRole; -import com.cloud.storage.ScopeType; +import javax.inject.Inject; +import java.util.HashMap; +import java.util.Map; public class SwiftImageStoreLifeCycleImpl implements ImageStoreLifeCycle { @@ -52,16 +48,6 @@ public class SwiftImageStoreLifeCycleImpl implements ImageStoreLifeCycle { @Inject ImageStoreProviderManager imageStoreMgr; - protected List _discoverers; - - public List getDiscoverers() { - return _discoverers; - } - - public void setDiscoverers(List _discoverers) { - this._discoverers = _discoverers; - } - public SwiftImageStoreLifeCycleImpl() { } @@ -99,50 +85,32 @@ public class SwiftImageStoreLifeCycleImpl implements ImageStoreLifeCycle { @Override public boolean attachCluster(DataStore store, ClusterScope scope) { - // TODO Auto-generated method stub return false; } @Override public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { - // TODO Auto-generated method stub return false; } @Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean dettach() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean unmanaged() { - // TODO Auto-generated method stub return false; } @Override public boolean maintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean cancelMaintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean deleteDataStore(DataStore store) { - // TODO Auto-generated method stub return false; } } diff --git a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java index 4c2f3894ef2..8d7c965ee07 100644 --- a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java @@ -18,27 +18,6 @@ */ package org.apache.cloudstack.storage.datastore.driver; -import java.util.Set; - -import javax.inject.Inject; - -import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; -import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult; -import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; -import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; -import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; -import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; -import org.apache.cloudstack.framework.async.AsyncCompletionCallback; -import org.apache.cloudstack.storage.command.CommandResult; -import org.apache.cloudstack.storage.command.CreateObjectCommand; -import org.apache.cloudstack.storage.command.DeleteCommand; -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; -import org.apache.cloudstack.storage.volume.VolumeObject; -import org.apache.log4j.Logger; - import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.ResizeVolumeAnswer; import com.cloud.agent.api.storage.ResizeVolumeCommand; @@ -58,6 +37,16 @@ import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.snapshot.SnapshotManager; import com.cloud.vm.dao.VMInstanceDao; +import org.apache.cloudstack.engine.subsystem.api.storage.*; +import org.apache.cloudstack.framework.async.AsyncCompletionCallback; +import org.apache.cloudstack.storage.command.CommandResult; +import org.apache.cloudstack.storage.command.CreateObjectCommand; +import org.apache.cloudstack.storage.command.DeleteCommand; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; +import org.apache.cloudstack.storage.volume.VolumeObject; +import org.apache.log4j.Logger; + +import javax.inject.Inject; public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver { private static final Logger s_logger = Logger.getLogger(CloudStackPrimaryDataStoreDriverImpl.class); @@ -84,12 +73,6 @@ public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDri @Inject EndPointSelector epSelector; - @Override - public String grantAccess(DataObject data, EndPoint ep) { - // TODO Auto-generated method stub - return null; - } - @Override public DataTO getTO(DataObject data) { return null; @@ -97,19 +80,6 @@ public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDri @Override public DataStoreTO getStoreTO(DataStore store) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean revokeAccess(DataObject data, EndPoint ep) { - // TODO Auto-generated method stub - return false; - } - - @Override - public Set listObjects(DataStore store) { - // TODO Auto-generated method stub return null; } @@ -126,7 +96,6 @@ public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDri @Override public void createAsync(DataObject data, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub String errMsg = null; Answer answer = null; if (data.getType() == DataObjectType.VOLUME) { @@ -168,13 +137,10 @@ public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDri @Override public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public boolean canCopy(DataObject srcData, DataObject destData) { - // TODO Auto-generated method stub return false; } @@ -205,8 +171,6 @@ public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDri @Override public void revertSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override diff --git a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java index 38dd5a9b276..2e0ff66baa1 100644 --- a/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java +++ b/plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java @@ -417,18 +417,6 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore return true; } - @Override - public boolean dettach() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean unmanaged() { - // TODO Auto-generated method stub - return false; - } - @Override public boolean maintain(DataStore dataStore) { storagePoolAutmation.maintain(dataStore); diff --git a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java index ad506d1793c..643c9334964 100644 --- a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java @@ -16,35 +16,20 @@ // under the License. package org.apache.cloudstack.storage.datastore.driver; -import java.net.URISyntaxException; -import java.util.Set; - -import javax.inject.Inject; - -import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; -import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult; -import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; -import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; -import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; -import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; -import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher; -import org.apache.cloudstack.framework.async.AsyncCompletionCallback; -import org.apache.cloudstack.framework.async.AsyncRpcConext; -import org.apache.cloudstack.storage.command.CommandResult; -import org.apache.cloudstack.storage.command.CreateObjectAnswer; -import org.apache.cloudstack.storage.command.CreateObjectCommand; -import org.apache.cloudstack.storage.datastore.DataObjectManager; -import org.apache.log4j.Logger; - import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.DataStoreTO; import com.cloud.agent.api.to.DataTO; import com.cloud.storage.dao.StoragePoolHostDao; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.storage.encoding.DecodedDataObject; -import com.cloud.utils.storage.encoding.Decoder; +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.framework.async.AsyncRpcConext; +import org.apache.cloudstack.storage.command.CommandResult; +import org.apache.cloudstack.storage.command.CreateObjectCommand; +import org.apache.cloudstack.storage.datastore.DataObjectManager; +import org.apache.log4j.Logger; + +import javax.inject.Inject; public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver { private static final Logger s_logger = Logger.getLogger(SamplePrimaryDataStoreDriverImpl.class); @@ -66,25 +51,15 @@ public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver @Override public DataStoreTO getStoreTO(DataStore store) { - // TODO Auto-generated method stub return null; } private class CreateVolumeContext extends AsyncRpcConext { private final DataObject volume; - - /** - * @param callback - */ public CreateVolumeContext(AsyncCompletionCallback callback, DataObject volume) { super(callback); this.volume = volume; } - - public DataObject getVolume() { - return this.volume; - } - } public Void createAsyncCallback(AsyncCallbackDispatcher callback, @@ -182,75 +157,25 @@ public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver ep.sendMessageAsync(createCmd, caller); } - @Override - public String grantAccess(DataObject object, EndPoint ep) { - // StoragePoolHostVO poolHost = - // storeHostDao.findByPoolHost(object.getDataStore().getId(), - // ep.getId()); - - String uri = object.getUri(); - try { - DecodedDataObject obj = Decoder.decode(uri); - if (obj.getPath() == null) { - // create an obj - EndPoint newEp = selector.select(object); - CreateObjectCommand createCmd = new CreateObjectCommand(null); - CreateObjectAnswer answer = (CreateObjectAnswer) ep.sendMessage(createCmd); - if (answer.getResult()) { - // dataObjMgr.update(object, answer.getPath(), - // answer.getSize()); - } else { - s_logger.debug("failed to create object" + answer.getDetails()); - throw new CloudRuntimeException("failed to create object" + answer.getDetails()); - } - } - - return object.getUri(); - } catch (URISyntaxException e) { - throw new CloudRuntimeException("uri parsed error", e); - } - } - - @Override - public boolean revokeAccess(DataObject vol, EndPoint ep) { - // TODO Auto-generated method stub - return false; - } - - @Override - public Set listObjects(DataStore store) { - // TODO Auto-generated method stub - return null; - } - @Override public void revertSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public boolean canCopy(DataObject srcData, DataObject destData) { - // TODO Auto-generated method stub return false; } @Override public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public void resize(DataObject data, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } } diff --git a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SamplePrimaryDataStoreLifeCycleImpl.java b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SamplePrimaryDataStoreLifeCycleImpl.java index 7ee8565e7e7..92538ad5f4b 100644 --- a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SamplePrimaryDataStoreLifeCycleImpl.java +++ b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/lifecycle/SamplePrimaryDataStoreLifeCycleImpl.java @@ -18,18 +18,12 @@ */ package org.apache.cloudstack.storage.datastore.lifecycle; -import java.util.List; -import java.util.Map; - -import javax.inject.Inject; - -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.EndPoint; -import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; -import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; -import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle; -import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; +import com.cloud.agent.api.StoragePoolInfo; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.StoragePoolStatus; +import org.apache.cloudstack.engine.subsystem.api.storage.*; import org.apache.cloudstack.storage.command.AttachPrimaryDataStoreCmd; import org.apache.cloudstack.storage.command.CreatePrimaryDataStoreCmd; import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager; @@ -37,11 +31,9 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; -import com.cloud.agent.api.StoragePoolInfo; -import com.cloud.host.HostVO; -import com.cloud.host.dao.HostDao; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.storage.StoragePoolStatus; +import javax.inject.Inject; +import java.util.List; +import java.util.Map; public class SamplePrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle { @Inject @@ -102,45 +94,28 @@ public class SamplePrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLife return true; } - @Override - public boolean dettach() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean unmanaged() { - // TODO Auto-generated method stub - return false; - } - @Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { - // TODO Auto-generated method stub return false; } @Override public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { - // TODO Auto-generated method stub return false; } @Override public boolean maintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean cancelMaintain(DataStore store) { - // TODO Auto-generated method stub return false; } @Override public boolean deleteDataStore(DataStore store) { - // TODO Auto-generated method stub return false; } diff --git a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/provider/SamplePrimaryDatastoreProviderImpl.java b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/provider/SamplePrimaryDatastoreProviderImpl.java index 87088214dbc..79ffc8fe4a1 100644 --- a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/provider/SamplePrimaryDatastoreProviderImpl.java +++ b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/provider/SamplePrimaryDatastoreProviderImpl.java @@ -40,8 +40,6 @@ public class SamplePrimaryDatastoreProviderImpl implements PrimaryDataStoreProvi PrimaryDataStoreProviderManager storeMgr; protected DataStoreLifeCycle lifecycle; - protected String uuid; - protected long id; @Override public String getName() { diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java index a296bab834a..960378c2821 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/driver/SolidfirePrimaryDataStoreDriver.java @@ -16,29 +16,14 @@ // under the License. package org.apache.cloudstack.storage.datastore.driver; -import java.util.Set; - -import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; -import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult; -import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; -import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; -import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; -import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; +import com.cloud.agent.api.to.DataStoreTO; +import com.cloud.agent.api.to.DataTO; +import org.apache.cloudstack.engine.subsystem.api.storage.*; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.storage.command.CommandResult; -import com.cloud.agent.api.to.DataStoreTO; -import com.cloud.agent.api.to.DataTO; - public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { - @Override - public String grantAccess(DataObject data, EndPoint ep) { - // TODO Auto-generated method stub - return null; - } - @Override public DataTO getTO(DataObject data) { return null; @@ -46,62 +31,36 @@ public class SolidfirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { @Override public DataStoreTO getStoreTO(DataStore store) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean revokeAccess(DataObject data, EndPoint ep) { - // TODO Auto-generated method stub - return false; - } - - @Override - public Set listObjects(DataStore store) { - // TODO Auto-generated method stub return null; } @Override public void createAsync(DataObject data, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public void deleteAsync(DataObject data, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public boolean canCopy(DataObject srcData, DataObject destData) { - // TODO Auto-generated method stub return false; } @Override public void revertSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public void resize(DataObject data, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } @Override public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback) { - // TODO Auto-generated method stub - } } diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/provider/SolidfirePrimaryDataStoreProvider.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/provider/SolidfirePrimaryDataStoreProvider.java index 03f241ef132..2965e8ff58e 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/provider/SolidfirePrimaryDataStoreProvider.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/provider/SolidfirePrimaryDataStoreProvider.java @@ -29,11 +29,6 @@ import org.springframework.stereotype.Component; public class SolidfirePrimaryDataStoreProvider implements PrimaryDataStoreProvider { private final String name = "Solidfire Primary Data Store Provider"; - public SolidfirePrimaryDataStoreProvider() { - - // TODO Auto-generated constructor stub - } - @Override public String getName() { return name; @@ -41,31 +36,26 @@ public class SolidfirePrimaryDataStoreProvider implements PrimaryDataStoreProvid @Override public DataStoreLifeCycle getDataStoreLifeCycle() { - // TODO Auto-generated method stub return null; } @Override public DataStoreDriver getDataStoreDriver() { - // TODO Auto-generated method stub return null; } @Override public HypervisorHostListener getHostListener() { - // TODO Auto-generated method stub return null; } @Override public boolean configure(Map params) { - // TODO Auto-generated method stub return false; } @Override public Set getTypes() { - // TODO Auto-generated method stub return null; } diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 5ee0fad8643..6bad4176da5 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -72,7 +72,10 @@ public enum Config { StorageOverprovisioningFactor("Storage", StoragePoolAllocator.class, String.class, "storage.overprovisioning.factor", "2", "Used for storage overprovisioning calculation; available storage will be (actualStorageSize * storage.overprovisioning.factor)", null, ConfigurationParameterScope.zone.toString()), StorageStatsInterval("Storage", ManagementServer.class, String.class, "storage.stats.interval", "60000", "The interval (in milliseconds) when storage stats (per host) are retrieved from agents.", null), MaxVolumeSize("Storage", ManagementServer.class, Integer.class, "storage.max.volume.size", "2000", "The maximum size for a volume (in GB).", null), - MaxUploadVolumeSize("Storage", ManagementServer.class, Integer.class, "storage.max.volume.upload.size", "500", "The maximum size for a uploaded volume(in GB).", null), + StorageCacheReplacementLRUTimeInterval("Storage", ManagementServer.class, Integer.class, "storage.cache.replacement.lru.interval", "30", "time interval for unsed data on cache storage (in days).", null), + StorageCacheReplacementEnabled("Storage", ManagementServer.class, Boolean.class, "storage.cache.replacement.enabled", "true", "enable or disable cache storage replacement algorithm.", null), + StorageCacheReplacementInterval("Storage", ManagementServer.class, Integer.class, "storage.cache.replacement.interval", "86400", "time interval between cache replacement threads (in seconds).", null), + MaxUploadVolumeSize("Storage", ManagementServer.class, Integer.class, "storage.max.volume.upload.size", "500", "The maximum size for a uploaded volume(in GB).", null), TotalRetries("Storage", AgentManager.class, Integer.class, "total.retries", "4", "The number of times each command sent to a host should be retried in case of failure.", null), StoragePoolMaxWaitSeconds("Storage", ManagementServer.class, Integer.class, "storage.pool.max.waitseconds", "3600", "Timeout (in seconds) to synchronize storage pool operations.", null), StorageTemplateCleanupEnabled("Storage", ManagementServer.class, Boolean.class, "storage.template.cleanup.enabled", "true", "Enable/disable template cleanup activity, only take effect when overall storage cleanup is enabled", null), diff --git a/server/src/com/cloud/server/StatsCollector.java b/server/src/com/cloud/server/StatsCollector.java index e5104358503..0d7fc3d65ee 100755 --- a/server/src/com/cloud/server/StatsCollector.java +++ b/server/src/com/cloud/server/StatsCollector.java @@ -185,13 +185,6 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc _executor.scheduleAtFixedRate(new VmDiskStatsTask(), vmDiskStatsInterval, vmDiskStatsInterval, TimeUnit.SECONDS); } - // -1 means we don't even start this thread to pick up any data. - if (volumeStatsInterval > 0) { - _executor.scheduleWithFixedDelay(new VolumeCollector(), 15000L, volumeStatsInterval, TimeUnit.MILLISECONDS); - } else { - s_logger.info("Disabling volume stats collector"); - } - //Schedule disk stats update task _diskStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("DiskStatsUpdater")); String aggregationRange = configs.get("usage.stats.job.aggregation.range"); @@ -548,13 +541,6 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc if (answer != null && answer.getResult()) { storageStats.put(storeId, (StorageStats)answer); s_logger.trace("HostId: "+storeId+ " Used: " + ((StorageStats)answer).getByteUsed() + " Total Available: " + ((StorageStats)answer).getCapacityBytes()); - //Seems like we have dynamically updated the sec. storage as prev. size and the current do not match - if (_storageStats.get(storeId)!=null && - _storageStats.get(storeId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()){ - ImageStoreVO imgStore = _imageStoreDao.findById(storeId); - imgStore.setTotalSize(((StorageStats)answer).getCapacityBytes()); - _imageStoreDao.update(storeId, imgStore); - } } } _storageStats = storageStats; @@ -603,79 +589,4 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc public StorageStats getStoragePoolStats(long id) { return _storagePoolStats.get(id); } - - class VolumeCollector implements Runnable { - @Override - public void run() { - try { - List volumes = _volsDao.listAll(); - Map> commandsByPool = new HashMap>(); - - for (VolumeVO volume : volumes) { - List commands = commandsByPool.get(volume.getPoolId()); - if (commands == null) { - commands = new ArrayList(); - commandsByPool.put(volume.getPoolId(), commands); - } - VolumeCommand vCommand = new VolumeCommand(); - vCommand.volumeId = volume.getId(); - vCommand.command = new GetFileStatsCommand(volume); - commands.add(vCommand); - } - ConcurrentHashMap volumeStats = new ConcurrentHashMap(); - for (Iterator iter = commandsByPool.keySet().iterator(); iter.hasNext();) { - Long poolId = iter.next(); - if(poolId != null) { - List commandsList = commandsByPool.get(poolId); - - long[] volumeIdArray = new long[commandsList.size()]; - Commands commands = new Commands(OnError.Continue); - for (int i = 0; i < commandsList.size(); i++) { - VolumeCommand vCommand = commandsList.get(i); - volumeIdArray[i] = vCommand.volumeId; - commands.addCommand(vCommand.command); - } - - List poolhosts = _storagePoolHostDao.listByPoolId(poolId); - for(StoragePoolHostVO poolhost : poolhosts) { - Answer[] answers = _agentMgr.send(poolhost.getHostId(), commands); - if (answers != null) { - long totalBytes = 0L; - for (int i = 0; i < answers.length; i++) { - if (answers[i].getResult()) { - VolumeStats vStats = (VolumeStats)answers[i]; - volumeStats.put(volumeIdArray[i], vStats); - totalBytes += vStats.getBytesUsed(); - } - } - break; - } - } - } - } - - // We replace the existing volumeStats so that it does not grow with no bounds - _volumeStats = volumeStats; - } catch (AgentUnavailableException e) { - s_logger.debug(e.getMessage()); - } catch (Throwable t) { - s_logger.error("Error trying to retrieve volume stats", t); - } - } - } - - private class VolumeCommand { - public long volumeId; - public GetFileStatsCommand command; - } - - public VolumeStats[] getVolumeStats(long[] ids) { - VolumeStats[] stats = new VolumeStats[ids.length]; - if (volumeStatsInterval > 0) { - for (int i = 0; i < ids.length; i++) { - stats[i] = _volumeStats.get(ids[i]); - } - } - return stats; - } } diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index 387e909d347..a8a133f1263 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -37,6 +37,7 @@ ALTER TABLE `cloud`.`load_balancer_vm_map` ADD state VARCHAR(40) NULL COMMENT 's alter table storage_pool add hypervisor varchar(32); alter table storage_pool change storage_provider_id storage_provider_name varchar(255); +alter table storage_pool change available_bytes used_bytes bigint unsigned; -- alter table template_host_ref add state varchar(255); -- alter table template_host_ref add update_count bigint unsigned; -- alter table template_host_ref add updated datetime; @@ -88,7 +89,8 @@ CREATE TABLE `cloud`.`image_store` ( `parent` varchar(255) COMMENT 'parent path for the storage server', `created` datetime COMMENT 'date the image store first signed on', `removed` datetime COMMENT 'date removed if not null', - `total_size` bigint unsigned COMMENT 'storage statistics', + `total_size` bigint unsigned COMMENT 'storage total size statistics', + `used_bytes` bigint unsigned COMMENT 'storage available bytes statistics', PRIMARY KEY(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -149,6 +151,7 @@ CREATE TABLE `cloud`.`template_store_ref` ( `destroyed` tinyint(1) COMMENT 'indicates whether the template_store entry was destroyed by the user or not', `is_copy` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'indicates whether this was copied ', `update_count` bigint unsigned, + `ref_cnt` bigint unsigned, `updated` datetime, PRIMARY KEY (`id`), -- CONSTRAINT `fk_template_store_ref__store_id` FOREIGN KEY `fk_template_store_ref__store_id` (`store_id`) REFERENCES `image_store` (`id`) ON DELETE CASCADE, @@ -183,6 +186,7 @@ CREATE TABLE `cloud`.`snapshot_store_ref` ( `state` varchar(255) NOT NULL, -- `removed` datetime COMMENT 'date removed if not null', `update_count` bigint unsigned, + `ref_cnt` bigint unsigned, `updated` datetime, PRIMARY KEY (`id`), INDEX `i_snapshot_store_ref__store_id`(`store_id`), @@ -210,6 +214,7 @@ CREATE TABLE `cloud`.`volume_store_ref` ( `state` varchar(255) NOT NULL, `destroyed` tinyint(1) COMMENT 'indicates whether the volume_host entry was destroyed by the user or not', `update_count` bigint unsigned, + `ref_cnt` bigint unsigned, `updated` datetime, PRIMARY KEY (`id`), CONSTRAINT `fk_volume_store_ref__store_id` FOREIGN KEY `fk_volume_store_ref__store_id` (`store_id`) REFERENCES `image_store` (`id`) ON DELETE CASCADE, diff --git a/test/pom.xml b/test/pom.xml index d4b88326fa2..92e62734ac4 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -75,7 +75,7 @@ compile - src + test test