Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
508f105
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 22, 2015
7086d64
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 22, 2015
51093af
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 22, 2015
7a90c01
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 22, 2015
6e56812
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 23, 2015
54f68f5
Removing the CheckStateCommand form the IF statement on LibvirtComput…
wilderrodrigues Apr 23, 2015
d730efb
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 23, 2015
28e5546
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 23, 2015
be1e517
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 23, 2015
4d216f1
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 23, 2015
40886b3
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 23, 2015
08a9523
Fixing assertion on the tests that are execting exceptions
wilderrodrigues Apr 23, 2015
7319a12
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 24, 2015
f14c7c2
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 24, 2015
6f757c6
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 29, 2015
cb46702
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 29, 2015
4472cad
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 29, 2015
8268d35
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 30, 2015
0d860af
Refactoring the LibvirtComputingResource
wilderrodrigues Apr 30, 2015
4887ce7
Refactoring the LibvirtComputingResource
wilderrodrigues May 1, 2015
5499eec
Refactoring the LibvirtComputingResource
wilderrodrigues May 1, 2015
6748a73
Refactoring the LibvirtComputingResource
wilderrodrigues May 1, 2015
3c8b217
Refactoring the LibvirtComputingResource
wilderrodrigues May 1, 2015
ff7ae9c
Refactoring the LibvirtComputingResource
wilderrodrigues May 2, 2015
52d9f0c
Refactoring the LibvirtComputingResource
wilderrodrigues May 5, 2015
bcf78d3
Refactoring the LibvirtComputingResource
wilderrodrigues May 5, 2015
b3913ca
Refactoring the LibvirtComputingResource
wilderrodrigues May 5, 2015
885b9e4
Renaming LibvirtConnectionWrapper to LibvirtUtilitiesHelper
wilderrodrigues May 5, 2015
0b1b2b6
Refactoring the LibvirtComputingResource
wilderrodrigues May 6, 2015
7fd43f3
Refactoring the LibvirtComputingResource
wilderrodrigues May 6, 2015
ae505e7
Refactoring the LibvirtComputingResource
wilderrodrigues May 6, 2015
08106e3
Refactoring the LibvirtComputingResource
wilderrodrigues May 6, 2015
09656ca
Refactoring the LibvirtComputingResource
wilderrodrigues May 6, 2015
74ad48d
Refactoring the LibvirtComputingResource
wilderrodrigues May 6, 2015
b284b84
Fixing method call on KVMGuru to reach StorageSubSystemCommand
wilderrodrigues May 6, 2015
f575206
Fixing testModifySshKeysCommand in the LibvirtComputingResourceTest c…
wilderrodrigues May 8, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/src/com/cloud/agent/api/SnapshotCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ protected SnapshotCommand() {
* is the value of that field If you have better ideas on how to
* get it, you are welcome.
*/
public SnapshotCommand(StoragePool pool, String secondaryStorageUrl, String snapshotUuid, String snapshotName, Long dcId, Long accountId, Long volumeId) {
// this.primaryStoragePoolNameLabel = pool.getUuid();
//this.primaryPool = new StorageFilerTO(pool);
public SnapshotCommand(final StoragePool pool, final String secondaryStorageUrl, final String snapshotUuid, final String snapshotName, final Long dcId, final Long accountId, final Long volumeId) {
primaryStoragePoolNameLabel = pool.getUuid();
primaryPool = new StorageFilerTO(pool);
this.snapshotUuid = snapshotUuid;
this.secondaryStorageUrl = secondaryStorageUrl;
this.dcId = dcId;
Expand Down Expand Up @@ -112,7 +112,7 @@ public String getVolumePath() {
return volumePath;
}

public void setVolumePath(String path) {
public void setVolumePath(final String path) {
volumePath = path;
}

Expand Down
65 changes: 0 additions & 65 deletions core/src/com/cloud/resource/CommandWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,81 +19,16 @@

package com.cloud.resource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;

import org.apache.log4j.Logger;

import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;


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

private static final Logger s_logger = Logger.getLogger(CommandWrapper.class);

/**
* @param T is the command to be used.
* @param R is the resource base to be used.
* @return A and the Answer from the command.
*/
public abstract A execute(T command, R serverResource);

/**
* Common method so we added it here.
*
* @param cmd
* @param proxyVmId
* @param proxyVmName
* @param proxyManagementIp
* @param cmdPort
* @return
*/
protected Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, final String proxyVmName, final String proxyManagementIp, final int cmdPort) {
String result = null;

final StringBuffer sb = new StringBuffer();
sb.append("http://").append(proxyManagementIp).append(":" + cmdPort).append("/cmd/getstatus");

boolean success = true;
try {
final URL url = new URL(sb.toString());
final URLConnection conn = url.openConnection();

// setting TIMEOUTs to avoid possible waiting until death situations
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);

final InputStream is = conn.getInputStream();
final BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.defaultCharset()));
final StringBuilder sb2 = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb2.append(line + "\n");
}
result = sb2.toString();
} catch (final IOException e) {
success = false;
} finally {
try {
is.close();
} catch (final IOException e) {
s_logger.warn("Exception when closing , console proxy address : " + proxyManagementIp);
success = false;
}
}
} catch (final IOException e) {
s_logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp);
success = false;
}

return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success, result);
}
}
79 changes: 79 additions & 0 deletions core/src/com/cloud/resource/RequestWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,93 @@

package com.cloud.resource;

import java.util.Hashtable;

import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;

public abstract class RequestWrapper {

@SuppressWarnings("rawtypes")
protected Hashtable<Class<? extends ServerResource>, Hashtable<Class<? extends Command>, CommandWrapper>> resources = new Hashtable<Class<? extends ServerResource>, Hashtable<Class<? extends Command>, CommandWrapper>>();

/**
* @param command to be executed.
* @return an Answer for the executed command.
*/
public abstract Answer execute(Command command, ServerResource serverResource);

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Hashtable<Class<? extends Command>, CommandWrapper> retrieveResource(final Command command, final Class<? extends ServerResource> resourceClass) {
Class<? extends ServerResource> keepResourceClass = resourceClass;
Hashtable<Class<? extends Command>, CommandWrapper> resource = resources.get(keepResourceClass);
while (resource == null) {
try {
final Class<? extends ServerResource> keepResourceClass2 = (Class<? extends ServerResource>) keepResourceClass.getSuperclass();
resource = resources.get(keepResourceClass2);

keepResourceClass = keepResourceClass2;
} catch (final ClassCastException e) {
throw new NullPointerException("No key found for '" + command.getClass() + "' in the Map!");
}
}
return resource;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
protected CommandWrapper<Command, Answer, ServerResource> retrieveCommands(final Class<? extends Command> commandClass,
final Hashtable<Class<? extends Command>, CommandWrapper> resourceCommands) {

Class<? extends Command> keepCommandClass = commandClass;
CommandWrapper<Command, Answer, ServerResource> commandWrapper = resourceCommands.get(keepCommandClass);
while (commandWrapper == null) {
try {
final Class<? extends Command> commandClass2 = (Class<? extends Command>) keepCommandClass.getSuperclass();

if (commandClass2 == null) {
throw new NullPointerException("All the COMMAND hierarchy tree has been visited but no compliant key has been found for '" + commandClass + "'.");
}

commandWrapper = resourceCommands.get(commandClass2);

keepCommandClass = commandClass2;
} catch (final NullPointerException e) {
// Will now traverse all the resource hierarchy. Returning null
// is not a problem.
// It is all being nicely checked and in case we do not have a
// resource, an Unsupported answer will be thrown by the base
// class.
return null;
}
}
return commandWrapper;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
protected CommandWrapper<Command, Answer, ServerResource> retryWhenAllFails(final Command command, final Class<? extends ServerResource> resourceClass,
final Hashtable<Class<? extends Command>, CommandWrapper> resourceCommands) {

Class<? extends ServerResource> keepResourceClass = resourceClass;
CommandWrapper<Command, Answer, ServerResource> commandWrapper = resourceCommands.get(command.getClass());
while (commandWrapper == null) {
// Could not find the command in the given resource, will traverse
// the family tree.
try {
final Class<? extends ServerResource> resourceClass2 = (Class<? extends ServerResource>) keepResourceClass.getSuperclass();

if (resourceClass2 == null) {
throw new NullPointerException("All the SERVER-RESOURCE hierarchy tree has been visited but no compliant key has been found for '" + command.getClass() + "'.");
}

final Hashtable<Class<? extends Command>, CommandWrapper> resourceCommands2 = retrieveResource(command,
(Class<? extends ServerResource>) keepResourceClass.getSuperclass());
keepResourceClass = resourceClass2;

commandWrapper = retrieveCommands(command.getClass(), resourceCommands2);
} catch (final NullPointerException e) {
throw e;
}
}
return commandWrapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@

package org.apache.cloudstack.storage.command;

import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DiskTO;

public final class AttachCommand extends Command implements StorageSubSystemCommand {
public final class AttachCommand extends StorageSubSystemCommand {
private DiskTO disk;
private String vmName;
private boolean inSeq = false;
private boolean inSeq;

public AttachCommand(DiskTO disk, String vmName) {
public AttachCommand(final DiskTO disk, final String vmName) {
super();
this.disk = disk;
this.vmName = vmName;
Expand All @@ -42,20 +41,20 @@ public DiskTO getDisk() {
return disk;
}

public void setDisk(DiskTO disk) {
public void setDisk(final DiskTO disk) {
this.disk = disk;
}

public String getVmName() {
return vmName;
}

public void setVmName(String vmName) {
public void setVmName(final String vmName) {
this.vmName = vmName;
}

@Override
public void setExecuteInSequence(boolean inSeq) {
public void setExecuteInSequence(final boolean inSeq) {
this.inSeq = inSeq;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@

package org.apache.cloudstack.storage.command;

import com.cloud.agent.api.Command;

public final class AttachPrimaryDataStoreCmd extends Command implements StorageSubSystemCommand {
public final class AttachPrimaryDataStoreCmd extends StorageSubSystemCommand {
@Override
public void setExecuteInSequence(boolean inSeq) {
public void setExecuteInSequence(final boolean inSeq) {

}

private final String dataStore;

public AttachPrimaryDataStoreCmd(String uri) {
public AttachPrimaryDataStoreCmd(final String uri) {
super();
dataStore = uri;
}
Expand Down
31 changes: 15 additions & 16 deletions core/src/org/apache/cloudstack/storage/command/CopyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,38 @@
import java.util.HashMap;
import java.util.Map;

import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataTO;

public final class CopyCommand extends Command implements StorageSubSystemCommand {
public final class CopyCommand extends StorageSubSystemCommand {
private DataTO srcTO;
private DataTO destTO;
private DataTO cacheTO;
private boolean executeInSequence = false;
private Map<String, String> options = new HashMap<String, String>();
private Map<String, String> options2 = new HashMap<String, String>();

public CopyCommand(DataTO srcData, DataTO destData, int timeout, boolean executeInSequence) {
public CopyCommand(final DataTO srcData, final DataTO destData, final int timeout, final boolean executeInSequence) {
super();
this.srcTO = srcData;
this.destTO = destData;
this.setWait(timeout);
srcTO = srcData;
destTO = destData;
setWait(timeout);
this.executeInSequence = executeInSequence;
}

public DataTO getDestTO() {
return this.destTO;
return destTO;
}

public void setSrcTO(DataTO srcTO) {
public void setSrcTO(final DataTO srcTO) {
this.srcTO = srcTO;
}

public void setDestTO(DataTO destTO) {
public void setDestTO(final DataTO destTO) {
this.destTO = destTO;
}

public DataTO getSrcTO() {
return this.srcTO;
return srcTO;
}

@Override
Expand All @@ -66,23 +65,23 @@ public DataTO getCacheTO() {
return cacheTO;
}

public void setCacheTO(DataTO cacheTO) {
public void setCacheTO(final DataTO cacheTO) {
this.cacheTO = cacheTO;
}

public int getWaitInMillSeconds() {
return this.getWait() * 1000;
return getWait() * 1000;
}

public void setOptions(Map<String, String> options) {
public void setOptions(final Map<String, String> options) {
this.options = options;
}

public Map<String, String> getOptions() {
return options;
}

public void setOptions2(Map<String, String> options2) {
public void setOptions2(final Map<String, String> options2) {
this.options2 = options2;
}

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

@Override
public void setExecuteInSequence(boolean inSeq) {
this.executeInSequence = inSeq;
public void setExecuteInSequence(final boolean inSeq) {
executeInSequence = inSeq;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

package org.apache.cloudstack.storage.command;

import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataTO;

public final class CreateObjectCommand extends Command implements StorageSubSystemCommand {
public final class CreateObjectCommand extends StorageSubSystemCommand {
private DataTO data;

public CreateObjectCommand(DataTO obj) {
public CreateObjectCommand(final DataTO obj) {
super();
data = obj;
}
Expand All @@ -44,7 +43,7 @@ public DataTO getData() {
}

@Override
public void setExecuteInSequence(boolean inSeq) {
public void setExecuteInSequence(final boolean inSeq) {

}
}
Loading