http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2251d5bb/engine/storage/src/org/apache/cloudstack/storage/volume/type/Unknown.java ---------------------------------------------------------------------- diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/Unknown.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/Unknown.java deleted file mode 100644 index c1a77b1..0000000 --- a/engine/storage/src/org/apache/cloudstack/storage/volume/type/Unknown.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.apache.cloudstack.storage.volume.type; - -public class Unknown extends VolumeTypeBase { - public Unknown() { - this.type = "Unknown"; - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2251d5bb/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeType.java ---------------------------------------------------------------------- diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeType.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeType.java deleted file mode 100644 index e423a5e..0000000 --- a/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeType.java +++ /dev/null @@ -1,22 +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.type; - -public interface VolumeType { -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2251d5bb/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeBase.java ---------------------------------------------------------------------- diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeBase.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeBase.java deleted file mode 100644 index 830873c..0000000 --- a/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeBase.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apache.cloudstack.storage.volume.type; - -public class VolumeTypeBase implements VolumeType { - protected String type = "Unknown"; - - @Override - public boolean equals(Object that) { - if (this == that) { - return true; - } - if (that instanceof String) { - if (this.toString().equalsIgnoreCase((String)that)) { - return true; - } - } else if (that instanceof VolumeTypeBase) { - VolumeTypeBase th = (VolumeTypeBase)that; - if (this.toString().equalsIgnoreCase(th.toString())) { - return true; - } - } else { - return false; - } - return false; - } - - @Override - public String toString() { - return type; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2251d5bb/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeHelper.java ---------------------------------------------------------------------- diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeHelper.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeHelper.java deleted file mode 100644 index 9443475..0000000 --- a/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeHelper.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apache.cloudstack.storage.volume.type; - -import java.util.List; - -import javax.inject.Inject; - -import org.springframework.stereotype.Component; - -@Component -public class VolumeTypeHelper { - static private List<VolumeType> types; - private static VolumeType defaultType = new Unknown(); - - @Inject - public void setTypes(List<VolumeType> types) { - VolumeTypeHelper.types = types; - } - - public static VolumeType getType(String type) { - for (VolumeType ty : types) { - if (ty.equals(type)) { - return ty; - } - } - return VolumeTypeHelper.defaultType; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2251d5bb/engine/storage/test/org/apache/cloudstack/storage/test/Future2.java ---------------------------------------------------------------------- diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/Future2.java b/engine/storage/test/org/apache/cloudstack/storage/test/Future2.java new file mode 100644 index 0000000..bc2fd7a --- /dev/null +++ b/engine/storage/test/org/apache/cloudstack/storage/test/Future2.java @@ -0,0 +1,114 @@ +/* + * 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.test; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + + +public class Future2<T> { + + private Callable<T> callable; + private Callable<T> success; + private Callable<T> failed; + private ExecutorService executor = Executors.newFixedThreadPool(2); + private Future<T> f; + + public class Func<T> implements Callable<T> { + private Callable<T> f; + private Callable<T> fs; + public T func() throws Exception { + return f.call(); + } + + public T success() throws Exception { + return fs.call(); + } + + public Func (Callable<T> f, Callable<T> s) { + this.f = f; + this.fs = s; + } + + + @Override + public T call() throws Exception { + func(); + success(); + return null; + } + + } + public Future2 (Callable<T> callable) { + this.callable = callable; + } + + public void onSuccess(Callable<T> s) { + this.success = s; + } + + public void go() { + Func<T> ft = new Func<T>(this.callable, this.success); + f = executor.submit(ft); + } + + public T get() { + try { + return this.f.get(); + } catch (InterruptedException e) { + return null; + } catch (ExecutionException e) { + // TODO Auto-generated catch block + return null; + } + } + + public void shutdown() { + this.executor.shutdown(); + } + + public static void main(String[] args) { + Callable<String> fun = new Callable<String> () { + + @Override + public String call() throws Exception { + System.out.println("execing"); + return "test"; + } + + }; + Future2<String> f2 = new Future2<String>(fun); + f2.onSuccess(new Callable<String>() { + + @Override + public String call() throws Exception { + Thread.sleep(1000); + System.out.println("success"); + return null; + } + }); + + f2.go(); + //f2.get(); + f2.shutdown(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2251d5bb/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java ---------------------------------------------------------------------- diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java b/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java index 8771d02..74967df 100644 --- a/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java +++ b/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java @@ -22,9 +22,18 @@ import static org.junit.Assert.*; import java.awt.List; import java.util.LinkedList; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import javax.inject.Inject; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; +import org.apache.cloudstack.engine.subsystem.api.storage.disktype.QCOW2; +import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VHD; +import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VMDK; +import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType; +import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTypeHelper; +import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeTypeHelper; import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl; import org.apache.cloudstack.storage.datastore.provider.DefaultPrimaryDatastoreProviderImpl; import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider; @@ -34,15 +43,8 @@ import org.apache.cloudstack.storage.image.format.ImageFormatHelper; import org.apache.cloudstack.storage.image.format.OVA; import org.apache.cloudstack.storage.image.format.Unknown; import org.apache.cloudstack.storage.volume.VolumeMotionService; -import org.apache.cloudstack.storage.volume.VolumeService; import org.apache.cloudstack.storage.volume.db.VolumeDao; -import org.apache.cloudstack.storage.volume.disktype.QCOW2; -import org.apache.cloudstack.storage.volume.disktype.VHD; -import org.apache.cloudstack.storage.volume.disktype.VMDK; -import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; -import org.apache.cloudstack.storage.volume.disktype.VolumeDiskTypeHelper; -import org.apache.cloudstack.storage.volume.type.Iso; -import org.apache.cloudstack.storage.volume.type.VolumeTypeHelper; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -58,7 +60,6 @@ import org.mockito.Mockito.*; import com.cloud.utils.component.ComponentInject; import com.cloud.utils.db.DB; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="storageContext.xml") public class volumeServiceTest { @@ -93,7 +94,7 @@ public class volumeServiceTest { fail("Not yet implemented"); } - @Test + //@Test public void test1() { System.out.println(VolumeTypeHelper.getType("Root")); System.out.println(VolumeDiskTypeHelper.getDiskType("vmdk")); @@ -125,4 +126,5 @@ public class volumeServiceTest { ComponentInject.inject(dpdsi); //assertNotNull(dpdsi.volumeDao); } + }
