Skip to content

Commit 45c0fa2

Browse files
Merge branch 'refactor/libvirt_resource' of https://github.com/schubergphilis/cloudstack
This closes apache#233
2 parents 60b6dc1 + f575206 commit 45c0fa2

82 files changed

Lines changed: 10150 additions & 3054 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎core/src/com/cloud/agent/api/SnapshotCommand.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ protected SnapshotCommand() {
5353
* is the value of that field If you have better ideas on how to
5454
* get it, you are welcome.
5555
*/
56-
public SnapshotCommand(StoragePool pool, String secondaryStorageUrl, String snapshotUuid, String snapshotName, Long dcId, Long accountId, Long volumeId) {
57-
// this.primaryStoragePoolNameLabel = pool.getUuid();
58-
//this.primaryPool = new StorageFilerTO(pool);
56+
public SnapshotCommand(final StoragePool pool, final String secondaryStorageUrl, final String snapshotUuid, final String snapshotName, final Long dcId, final Long accountId, final Long volumeId) {
57+
primaryStoragePoolNameLabel = pool.getUuid();
58+
primaryPool = new StorageFilerTO(pool);
5959
this.snapshotUuid = snapshotUuid;
6060
this.secondaryStorageUrl = secondaryStorageUrl;
6161
this.dcId = dcId;
@@ -112,7 +112,7 @@ public String getVolumePath() {
112112
return volumePath;
113113
}
114114

115-
public void setVolumePath(String path) {
115+
public void setVolumePath(final String path) {
116116
volumePath = path;
117117
}
118118

‎core/src/com/cloud/resource/CommandWrapper.java‎

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -19,81 +19,16 @@
1919

2020
package com.cloud.resource;
2121

22-
import java.io.BufferedReader;
23-
import java.io.IOException;
24-
import java.io.InputStream;
25-
import java.io.InputStreamReader;
26-
import java.net.URL;
27-
import java.net.URLConnection;
28-
import java.nio.charset.Charset;
29-
30-
import org.apache.log4j.Logger;
31-
3222
import com.cloud.agent.api.Answer;
3323
import com.cloud.agent.api.Command;
34-
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
3524

3625

3726
public abstract class CommandWrapper<T extends Command, A extends Answer, R extends ServerResource> {
3827

39-
private static final Logger s_logger = Logger.getLogger(CommandWrapper.class);
40-
4128
/**
4229
* @param T is the command to be used.
4330
* @param R is the resource base to be used.
4431
* @return A and the Answer from the command.
4532
*/
4633
public abstract A execute(T command, R serverResource);
47-
48-
/**
49-
* Common method so we added it here.
50-
*
51-
* @param cmd
52-
* @param proxyVmId
53-
* @param proxyVmName
54-
* @param proxyManagementIp
55-
* @param cmdPort
56-
* @return
57-
*/
58-
protected Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, final String proxyVmName, final String proxyManagementIp, final int cmdPort) {
59-
String result = null;
60-
61-
final StringBuffer sb = new StringBuffer();
62-
sb.append("http://").append(proxyManagementIp).append(":" + cmdPort).append("/cmd/getstatus");
63-
64-
boolean success = true;
65-
try {
66-
final URL url = new URL(sb.toString());
67-
final URLConnection conn = url.openConnection();
68-
69-
// setting TIMEOUTs to avoid possible waiting until death situations
70-
conn.setConnectTimeout(5000);
71-
conn.setReadTimeout(5000);
72-
73-
final InputStream is = conn.getInputStream();
74-
final BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.defaultCharset()));
75-
final StringBuilder sb2 = new StringBuilder();
76-
String line = null;
77-
try {
78-
while ((line = reader.readLine()) != null) {
79-
sb2.append(line + "\n");
80-
}
81-
result = sb2.toString();
82-
} catch (final IOException e) {
83-
success = false;
84-
} finally {
85-
try {
86-
is.close();
87-
} catch (final IOException e) {
88-
s_logger.warn("Exception when closing , console proxy address : " + proxyManagementIp);
89-
success = false;
90-
}
91-
}
92-
} catch (final IOException e) {
93-
s_logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp);
94-
success = false;
95-
}
96-
97-
return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success, result);
98-
}
9934
}

‎core/src/com/cloud/resource/RequestWrapper.java‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,93 @@
1919

2020
package com.cloud.resource;
2121

22+
import java.util.Hashtable;
23+
2224
import com.cloud.agent.api.Answer;
2325
import com.cloud.agent.api.Command;
2426

2527
public abstract class RequestWrapper {
2628

29+
@SuppressWarnings("rawtypes")
30+
protected Hashtable<Class<? extends ServerResource>, Hashtable<Class<? extends Command>, CommandWrapper>> resources = new Hashtable<Class<? extends ServerResource>, Hashtable<Class<? extends Command>, CommandWrapper>>();
31+
2732
/**
2833
* @param command to be executed.
2934
* @return an Answer for the executed command.
3035
*/
3136
public abstract Answer execute(Command command, ServerResource serverResource);
37+
38+
@SuppressWarnings({ "rawtypes", "unchecked" })
39+
protected Hashtable<Class<? extends Command>, CommandWrapper> retrieveResource(final Command command, final Class<? extends ServerResource> resourceClass) {
40+
Class<? extends ServerResource> keepResourceClass = resourceClass;
41+
Hashtable<Class<? extends Command>, CommandWrapper> resource = resources.get(keepResourceClass);
42+
while (resource == null) {
43+
try {
44+
final Class<? extends ServerResource> keepResourceClass2 = (Class<? extends ServerResource>) keepResourceClass.getSuperclass();
45+
resource = resources.get(keepResourceClass2);
46+
47+
keepResourceClass = keepResourceClass2;
48+
} catch (final ClassCastException e) {
49+
throw new NullPointerException("No key found for '" + command.getClass() + "' in the Map!");
50+
}
51+
}
52+
return resource;
53+
}
54+
55+
@SuppressWarnings({ "rawtypes", "unchecked" })
56+
protected CommandWrapper<Command, Answer, ServerResource> retrieveCommands(final Class<? extends Command> commandClass,
57+
final Hashtable<Class<? extends Command>, CommandWrapper> resourceCommands) {
58+
59+
Class<? extends Command> keepCommandClass = commandClass;
60+
CommandWrapper<Command, Answer, ServerResource> commandWrapper = resourceCommands.get(keepCommandClass);
61+
while (commandWrapper == null) {
62+
try {
63+
final Class<? extends Command> commandClass2 = (Class<? extends Command>) keepCommandClass.getSuperclass();
64+
65+
if (commandClass2 == null) {
66+
throw new NullPointerException("All the COMMAND hierarchy tree has been visited but no compliant key has been found for '" + commandClass + "'.");
67+
}
68+
69+
commandWrapper = resourceCommands.get(commandClass2);
70+
71+
keepCommandClass = commandClass2;
72+
} catch (final NullPointerException e) {
73+
// Will now traverse all the resource hierarchy. Returning null
74+
// is not a problem.
75+
// It is all being nicely checked and in case we do not have a
76+
// resource, an Unsupported answer will be thrown by the base
77+
// class.
78+
return null;
79+
}
80+
}
81+
return commandWrapper;
82+
}
83+
84+
@SuppressWarnings({ "rawtypes", "unchecked" })
85+
protected CommandWrapper<Command, Answer, ServerResource> retryWhenAllFails(final Command command, final Class<? extends ServerResource> resourceClass,
86+
final Hashtable<Class<? extends Command>, CommandWrapper> resourceCommands) {
87+
88+
Class<? extends ServerResource> keepResourceClass = resourceClass;
89+
CommandWrapper<Command, Answer, ServerResource> commandWrapper = resourceCommands.get(command.getClass());
90+
while (commandWrapper == null) {
91+
// Could not find the command in the given resource, will traverse
92+
// the family tree.
93+
try {
94+
final Class<? extends ServerResource> resourceClass2 = (Class<? extends ServerResource>) keepResourceClass.getSuperclass();
95+
96+
if (resourceClass2 == null) {
97+
throw new NullPointerException("All the SERVER-RESOURCE hierarchy tree has been visited but no compliant key has been found for '" + command.getClass() + "'.");
98+
}
99+
100+
final Hashtable<Class<? extends Command>, CommandWrapper> resourceCommands2 = retrieveResource(command,
101+
(Class<? extends ServerResource>) keepResourceClass.getSuperclass());
102+
keepResourceClass = resourceClass2;
103+
104+
commandWrapper = retrieveCommands(command.getClass(), resourceCommands2);
105+
} catch (final NullPointerException e) {
106+
throw e;
107+
}
108+
}
109+
return commandWrapper;
110+
}
32111
}

‎core/src/org/apache/cloudstack/storage/command/AttachCommand.java‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919

2020
package org.apache.cloudstack.storage.command;
2121

22-
import com.cloud.agent.api.Command;
2322
import com.cloud.agent.api.to.DiskTO;
2423

25-
public final class AttachCommand extends Command implements StorageSubSystemCommand {
24+
public final class AttachCommand extends StorageSubSystemCommand {
2625
private DiskTO disk;
2726
private String vmName;
28-
private boolean inSeq = false;
27+
private boolean inSeq;
2928

30-
public AttachCommand(DiskTO disk, String vmName) {
29+
public AttachCommand(final DiskTO disk, final String vmName) {
3130
super();
3231
this.disk = disk;
3332
this.vmName = vmName;
@@ -42,20 +41,20 @@ public DiskTO getDisk() {
4241
return disk;
4342
}
4443

45-
public void setDisk(DiskTO disk) {
44+
public void setDisk(final DiskTO disk) {
4645
this.disk = disk;
4746
}
4847

4948
public String getVmName() {
5049
return vmName;
5150
}
5251

53-
public void setVmName(String vmName) {
52+
public void setVmName(final String vmName) {
5453
this.vmName = vmName;
5554
}
5655

5756
@Override
58-
public void setExecuteInSequence(boolean inSeq) {
57+
public void setExecuteInSequence(final boolean inSeq) {
5958
this.inSeq = inSeq;
6059
}
6160
}

‎core/src/org/apache/cloudstack/storage/command/AttachPrimaryDataStoreCmd.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@
1919

2020
package org.apache.cloudstack.storage.command;
2121

22-
import com.cloud.agent.api.Command;
2322

24-
public final class AttachPrimaryDataStoreCmd extends Command implements StorageSubSystemCommand {
23+
public final class AttachPrimaryDataStoreCmd extends StorageSubSystemCommand {
2524
@Override
26-
public void setExecuteInSequence(boolean inSeq) {
25+
public void setExecuteInSequence(final boolean inSeq) {
2726

2827
}
2928

3029
private final String dataStore;
3130

32-
public AttachPrimaryDataStoreCmd(String uri) {
31+
public AttachPrimaryDataStoreCmd(final String uri) {
3332
super();
3433
dataStore = uri;
3534
}

‎core/src/org/apache/cloudstack/storage/command/CopyCommand.java‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,38 @@
2222
import java.util.HashMap;
2323
import java.util.Map;
2424

25-
import com.cloud.agent.api.Command;
2625
import com.cloud.agent.api.to.DataTO;
2726

28-
public final class CopyCommand extends Command implements StorageSubSystemCommand {
27+
public final class CopyCommand extends StorageSubSystemCommand {
2928
private DataTO srcTO;
3029
private DataTO destTO;
3130
private DataTO cacheTO;
3231
private boolean executeInSequence = false;
3332
private Map<String, String> options = new HashMap<String, String>();
3433
private Map<String, String> options2 = new HashMap<String, String>();
3534

36-
public CopyCommand(DataTO srcData, DataTO destData, int timeout, boolean executeInSequence) {
35+
public CopyCommand(final DataTO srcData, final DataTO destData, final int timeout, final boolean executeInSequence) {
3736
super();
38-
this.srcTO = srcData;
39-
this.destTO = destData;
40-
this.setWait(timeout);
37+
srcTO = srcData;
38+
destTO = destData;
39+
setWait(timeout);
4140
this.executeInSequence = executeInSequence;
4241
}
4342

4443
public DataTO getDestTO() {
45-
return this.destTO;
44+
return destTO;
4645
}
4746

48-
public void setSrcTO(DataTO srcTO) {
47+
public void setSrcTO(final DataTO srcTO) {
4948
this.srcTO = srcTO;
5049
}
5150

52-
public void setDestTO(DataTO destTO) {
51+
public void setDestTO(final DataTO destTO) {
5352
this.destTO = destTO;
5453
}
5554

5655
public DataTO getSrcTO() {
57-
return this.srcTO;
56+
return srcTO;
5857
}
5958

6059
@Override
@@ -66,23 +65,23 @@ public DataTO getCacheTO() {
6665
return cacheTO;
6766
}
6867

69-
public void setCacheTO(DataTO cacheTO) {
68+
public void setCacheTO(final DataTO cacheTO) {
7069
this.cacheTO = cacheTO;
7170
}
7271

7372
public int getWaitInMillSeconds() {
74-
return this.getWait() * 1000;
73+
return getWait() * 1000;
7574
}
7675

77-
public void setOptions(Map<String, String> options) {
76+
public void setOptions(final Map<String, String> options) {
7877
this.options = options;
7978
}
8079

8180
public Map<String, String> getOptions() {
8281
return options;
8382
}
8483

85-
public void setOptions2(Map<String, String> options2) {
84+
public void setOptions2(final Map<String, String> options2) {
8685
this.options2 = options2;
8786
}
8887

@@ -91,7 +90,7 @@ public Map<String, String> getOptions2() {
9190
}
9291

9392
@Override
94-
public void setExecuteInSequence(boolean inSeq) {
95-
this.executeInSequence = inSeq;
93+
public void setExecuteInSequence(final boolean inSeq) {
94+
executeInSequence = inSeq;
9695
}
9796
}

‎core/src/org/apache/cloudstack/storage/command/CreateObjectCommand.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919

2020
package org.apache.cloudstack.storage.command;
2121

22-
import com.cloud.agent.api.Command;
2322
import com.cloud.agent.api.to.DataTO;
2423

25-
public final class CreateObjectCommand extends Command implements StorageSubSystemCommand {
24+
public final class CreateObjectCommand extends StorageSubSystemCommand {
2625
private DataTO data;
2726

28-
public CreateObjectCommand(DataTO obj) {
27+
public CreateObjectCommand(final DataTO obj) {
2928
super();
3029
data = obj;
3130
}
@@ -44,7 +43,7 @@ public DataTO getData() {
4443
}
4544

4645
@Override
47-
public void setExecuteInSequence(boolean inSeq) {
46+
public void setExecuteInSequence(final boolean inSeq) {
4847

4948
}
5049
}

0 commit comments

Comments
 (0)