Check all warnings in core and fix where applicable, also apply autoformatting on save.

This commit is contained in:
Hugo Trippaers 2013-09-21 16:15:36 +08:00
parent bb8b7340f3
commit 4945d465bf
21 changed files with 580 additions and 575 deletions

View File

@ -20,9 +20,6 @@ import java.util.List;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import com.cloud.agent.api.to.DiskTO;
import com.cloud.agent.api.to.VolumeTO;
public class MigrateWithStorageAnswer extends Answer {
List<VolumeObjectTO> volumeTos;

View File

@ -20,8 +20,6 @@ import java.util.List;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import com.cloud.agent.api.to.VolumeTO;
public class MigrateWithStorageCompleteAnswer extends Answer {
List<VolumeObjectTO> volumeTos;

View File

@ -16,7 +16,6 @@
// under the License.
package com.cloud.agent.api;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.vm.VirtualMachine;
public class RebootCommand extends Command {

View File

@ -20,7 +20,6 @@ import java.util.List;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.api.to.NicTO;
/**
* LoadBalancerConfigCommand sends the load balancer configuration

View File

@ -17,7 +17,6 @@
package com.cloud.agent.api.routing;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.api.to.NicTO;
/**
* LoadBalancerConfigCommand sends the load balancer configuration

View File

@ -20,9 +20,7 @@ package com.cloud.agent.api.routing;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.cloud.agent.api.to.NetworkACLTO;
import com.cloud.agent.api.to.NicTO;

View File

@ -41,30 +41,30 @@ public class UploadCommand extends AbstractUploadCommand implements InternalIden
this.template = new TemplateTO(template);
this.url = url;
this.installPath = installPath;
this.checksum = template.getChecksum();
this.id = template.getId();
this.templateSizeInBytes = sizeInBytes;
checksum = template.getChecksum();
id = template.getId();
templateSizeInBytes = sizeInBytes;
}
public UploadCommand(String url, long id, long sizeInBytes, String installPath, Type type){
this.template = null;
template = null;
this.url = url;
this.installPath = installPath;
this.id = id;
this.type = type;
this.templateSizeInBytes = sizeInBytes;
templateSizeInBytes = sizeInBytes;
}
protected UploadCommand() {
}
public UploadCommand(UploadCommand that) {
this.template = that.template;
this.url = that.url;
this.installPath = that.installPath;
this.checksum = that.getChecksum();
this.id = that.id;
template = that.template;
url = that.url;
installPath = that.installPath;
checksum = that.getChecksum();
id = that.id;
}
public String getDescription() {
@ -114,6 +114,7 @@ public class UploadCommand extends AbstractUploadCommand implements InternalIden
this.templateSizeInBytes = templateSizeInBytes;
}
@Override
public long getId() {
return id;
}

View File

@ -108,7 +108,6 @@ public class VirtualRoutingResource implements Manager {
private String _firewallPath;
private String _loadbPath;
private String _dhcpEntryPath;
private String _vmDataPath;
private String _publicEthIf;
private String _privateEthIf;
private String _bumpUpPriorityPath;

View File

@ -31,14 +31,6 @@ import java.util.zip.GZIPOutputStream;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
import com.cloud.exception.UnsupportedVersionException;
import com.cloud.serializer.GsonHelper;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
@ -50,6 +42,15 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.stream.JsonReader;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
import com.cloud.exception.UnsupportedVersionException;
import com.cloud.serializer.GsonHelper;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.exception.CloudRuntimeException;
/**
* Request is a simple wrapper around command and answer to add sequencing,
* versioning, and flags. Note that the version here represents the changes
@ -158,14 +159,14 @@ public class Request {
}
protected Request(final Request that, final Command[] cmds) {
this._ver = that._ver;
this._seq = that._seq;
_ver = that._ver;
_seq = that._seq;
setInSequence(that.executeInSequence());
setStopOnError(that.stopOnError());
this._cmds = cmds;
this._mgmtId = that._mgmtId;
this._via = that._via;
this._agentId = that._agentId;
_cmds = cmds;
_mgmtId = that._mgmtId;
_via = that._via;
_agentId = that._agentId;
setFromServer(!that.isFromServer());
}
@ -447,7 +448,7 @@ public class Request {
if (version.ordinal() != Version.v1.ordinal() && version.ordinal() != Version.v3.ordinal()) {
throw new UnsupportedVersionException("This version is no longer supported: " + version.toString(), UnsupportedVersionException.IncompatibleVersion);
}
final byte reserved = buff.get(); // tossed away for now.
buff.get();
final short flags = buff.getShort();
final boolean isRequest = (flags & FLAG_REQUEST) > 0;

View File

@ -18,6 +18,11 @@ package com.cloud.exception;
public class UsageServerException extends CloudException {
/**
*
*/
private static final long serialVersionUID = -8398313106067116466L;
public UsageServerException() {
}

View File

@ -17,7 +17,6 @@
package com.cloud.storage;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -41,7 +40,7 @@ public class JavaStorageLayer implements StorageLayer {
public JavaStorageLayer(boolean makeWorldWriteable) {
this();
this._makeWorldWriteable = makeWorldWriteable;
_makeWorldWriteable = makeWorldWriteable;
}
@Override
@ -171,7 +170,7 @@ public class JavaStorageLayer implements StorageLayer {
File dir = new File(dirName);
if (dir.exists()) {
String uniqDirName = dir.getAbsolutePath() + File.separator + UUID.randomUUID().toString();
if (this.mkdir(uniqDirName)) {
if (mkdir(uniqDirName)) {
return new File(uniqDirName);
}
}
@ -219,6 +218,7 @@ public class JavaStorageLayer implements StorageLayer {
return dirPaths;
}
@Override
public boolean setWorldReadableAndWriteable(File file) {
return (file.setReadable(true, false) && file.setWritable(true, false));
}

View File

@ -21,8 +21,6 @@ import com.cloud.agent.api.storage.CopyVolumeAnswer;
import com.cloud.agent.api.storage.CopyVolumeCommand;
import com.cloud.agent.api.storage.CreateAnswer;
import com.cloud.agent.api.storage.CreateCommand;
import com.cloud.agent.api.storage.CreateVolumeOVAAnswer;
import com.cloud.agent.api.storage.CreateVolumeOVACommand;
import com.cloud.agent.api.storage.DestroyCommand;
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;

View File

@ -39,7 +39,6 @@ public class FtpTemplateUploader implements TemplateUploader {
private String sourcePath;
private String ftpUrl;
private UploadCompleteCallback completionCallback;
private boolean resume;
private BufferedInputStream inputStream = null;
private BufferedOutputStream outputStream = null;
private static final int CHUNK_SIZE = 1024*1024; //1M
@ -47,12 +46,13 @@ public class FtpTemplateUploader implements TemplateUploader {
public FtpTemplateUploader(String sourcePath, String url, UploadCompleteCallback callback, long entitySizeinBytes){
this.sourcePath = sourcePath;
this.ftpUrl = url;
this.completionCallback = callback;
ftpUrl = url;
completionCallback = callback;
this.entitySizeinBytes = entitySizeinBytes;
}
@Override
public long upload(UploadCompleteCallback callback )
{
@ -65,7 +65,7 @@ public class FtpTemplateUploader implements TemplateUploader {
}
Date start = new Date();
new Date();
StringBuffer sb = new StringBuffer(ftpUrl);
// check for authentication else assume its anonymous access.
@ -185,7 +185,6 @@ public class FtpTemplateUploader implements TemplateUploader {
@Override
public void setResume(boolean resume) {
this.resume = resume;
}

View File

@ -22,14 +22,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.Date;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import org.apache.commons.httpclient.ChunkedInputStream;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
@ -46,9 +41,10 @@ import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.log4j.Logger;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import com.cloud.agent.api.storage.Proxy;
import com.cloud.storage.StorageLayer;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.Pair;
import com.cloud.utils.UriUtils;
@ -83,17 +79,18 @@ public class HttpTemplateDownloader implements TemplateDownloader {
public HttpTemplateDownloader (StorageLayer storageLayer, String downloadUrl, String toDir, DownloadCompleteCallback callback, long maxTemplateSizeInBytes, String user, String password, Proxy proxy, ResourceType resourceType) {
this._storage = storageLayer;
_storage = storageLayer;
this.downloadUrl = downloadUrl;
this.setToDir(toDir);
this.status = TemplateDownloader.Status.NOT_STARTED;
setToDir(toDir);
status = TemplateDownloader.Status.NOT_STARTED;
this.resourceType = resourceType;
this.MAX_TEMPLATE_SIZE_IN_BYTES = maxTemplateSizeInBytes;
MAX_TEMPLATE_SIZE_IN_BYTES = maxTemplateSizeInBytes;
this.totalBytes = 0;
this.client = new HttpClient(s_httpClientManager);
totalBytes = 0;
client = new HttpClient(s_httpClientManager);
myretryhandler = new HttpMethodRetryHandler() {
@Override
public boolean retryMethod(
final HttpMethod method,
final IOException exception,
@ -117,9 +114,9 @@ public class HttpTemplateDownloader implements TemplateDownloader {
};
try {
this.request = new GetMethod(downloadUrl);
this.request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler);
this.completionCallback = callback;
request = new GetMethod(downloadUrl);
request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler);
completionCallback = callback;
//this.request.setFollowRedirects(false);
File f = File.createTempFile("dnld", "tmp_", new File(toDir));
@ -236,8 +233,8 @@ public class HttpTemplateDownloader implements TemplateDownloader {
remoteSize = MAX_TEMPLATE_SIZE_IN_BYTES;
}
InputStream in = !chunked?new BufferedInputStream(request.getResponseBodyAsStream())
: new ChunkedInputStream(request.getResponseBodyAsStream());
InputStream in = !chunked ? new BufferedInputStream(request.getResponseBodyAsStream()) : new ChunkedInputStream(
request.getResponseBodyAsStream());
RandomAccessFile out = new RandomAccessFile(file, "rwd");
out.seek(localFileSize);
@ -266,6 +263,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
}
errorString = "Downloaded " + totalBytes + " bytes " + downloaded;
downloadTime += finish.getTime() - start.getTime();
in.close();
out.close();
return totalBytes;
@ -297,16 +295,19 @@ public class HttpTemplateDownloader implements TemplateDownloader {
return file.getAbsolutePath();
}
@Override
public TemplateDownloader.Status getStatus() {
return status;
}
@Override
public long getDownloadTime() {
return downloadTime;
}
@Override
public long getDownloadedBytes() {
return totalBytes;
}
@ -381,6 +382,7 @@ public class HttpTemplateDownloader implements TemplateDownloader {
return getToFile();
}
@Override
public void setResume(boolean resume) {
this.resume = resume;
}
@ -393,14 +395,15 @@ public class HttpTemplateDownloader implements TemplateDownloader {
return toDir;
}
@Override
public long getMaxTemplateSizeInBytes() {
return this.MAX_TEMPLATE_SIZE_IN_BYTES;
return MAX_TEMPLATE_SIZE_IN_BYTES;
}
public static void main(String[] args) {
String url ="http:// dev.mysql.com/get/Downloads/MySQL-5.0/mysql-noinstall-5.0.77-win32.zip/from/http://mirror.services.wisc.edu/mysql/";
try {
URI uri = new java.net.URI(url);
new java.net.URI(url);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();

View File

@ -64,6 +64,8 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T
FileChannel fic = null;
FileChannel foc = null;
FileInputStream fis = null;
FileOutputStream fos = null;
try {
if (_storage != null) {
@ -72,7 +74,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T
}
ByteBuffer buffer = ByteBuffer.allocate(1024 * 512);
FileInputStream fis;
try {
fis = new FileInputStream(src);
} catch (FileNotFoundException e) {
@ -81,7 +83,6 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T
return -1;
}
fic = fis.getChannel();
FileOutputStream fos;
try {
fos = new FileOutputStream(dst);
} catch (FileNotFoundException e) {
@ -91,7 +92,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T
foc = fos.getChannel();
_remoteSize = src.length();
this._totalBytes = 0;
_totalBytes = 0;
_status = TemplateDownloader.Status.IN_PROGRESS;
try {
@ -133,6 +134,20 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
if (_status == Status.UNRECOVERABLE_ERROR && dst.exists()) {
dst.delete();
}

View File

@ -25,9 +25,8 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.exception.InternalErrorException;
import com.cloud.storage.StorageLayer;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.template.Processor.FormatInfo;
import com.cloud.storage.StorageLayer;
import com.cloud.utils.component.AdapterBase;
@Local(value=Processor.class)

View File

@ -24,7 +24,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import org.apache.commons.httpclient.ChunkedInputStream;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
@ -43,8 +42,6 @@ import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.ProgressEvent;
import com.amazonaws.services.s3.model.ProgressListener;
@ -52,6 +49,9 @@ import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.StorageClass;
import com.amazonaws.services.s3.transfer.TransferManager;
import com.amazonaws.services.s3.transfer.Upload;
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
import com.cloud.agent.api.storage.Proxy;
import com.cloud.agent.api.to.S3TO;
import com.cloud.utils.Pair;
@ -89,15 +89,15 @@ public class S3TemplateDownloader implements TemplateDownloader {
public S3TemplateDownloader(S3TO storageLayer, String downloadUrl, String installPath,
DownloadCompleteCallback callback, long maxTemplateSizeInBytes, String user, String password, Proxy proxy,
ResourceType resourceType) {
this.s3 = storageLayer;
s3 = storageLayer;
this.downloadUrl = downloadUrl;
this.installPath = installPath;
this.status = TemplateDownloader.Status.NOT_STARTED;
status = TemplateDownloader.Status.NOT_STARTED;
this.resourceType = resourceType;
this.maxTemplateSizeInByte = maxTemplateSizeInBytes;
maxTemplateSizeInByte = maxTemplateSizeInBytes;
this.totalBytes = 0;
this.client = new HttpClient(s_httpClientManager);
totalBytes = 0;
client = new HttpClient(s_httpClientManager);
myretryhandler = new HttpMethodRetryHandler() {
@Override
@ -121,12 +121,12 @@ public class S3TemplateDownloader implements TemplateDownloader {
};
try {
this.request = new GetMethod(downloadUrl);
this.request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler);
this.completionCallback = callback;
request = new GetMethod(downloadUrl);
request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler);
completionCallback = callback;
Pair<String, Integer> hostAndPort = UriUtils.validateUrl(downloadUrl);
this.fileName = StringUtils.substringAfterLast(downloadUrl, "/");
fileName = StringUtils.substringAfterLast(downloadUrl, "/");
if (proxy != null) {
client.getHostConfiguration().setProxy(proxy.getHost(), proxy.getPort());
@ -388,7 +388,7 @@ public class S3TemplateDownloader implements TemplateDownloader {
@Override
public String getDownloadLocalPath() {
return this.s3Key;
return s3Key;
}
@Override
@ -398,7 +398,7 @@ public class S3TemplateDownloader implements TemplateDownloader {
@Override
public long getMaxTemplateSizeInBytes() {
return this.maxTemplateSizeInByte;
return maxTemplateSizeInByte;
}
@Override

View File

@ -22,9 +22,10 @@ import java.net.URISyntaxException;
import org.apache.log4j.Logger;
import com.trilead.ssh2.SCPClient;
import com.cloud.storage.StorageLayer;
import com.cloud.utils.exception.CloudRuntimeException;
import com.trilead.ssh2.SCPClient;
public class ScpTemplateDownloader extends TemplateDownloaderBase implements TemplateDownloader {
private static final Logger s_logger = Logger.getLogger(ScpTemplateDownloader.class);
@ -83,7 +84,6 @@ public class ScpTemplateDownloader extends TemplateDownloaderBase implements Tem
if (port == -1) {
port = 22;
}
long length = 0;
File file = new File(_toFile);
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(uri.getHost(), port);

View File

@ -16,9 +16,6 @@
// under the License.
package com.cloud.storage.template;
import com.cloud.storage.template.TemplateUploader.UploadCompleteCallback;
import com.cloud.storage.template.TemplateUploader.Status;
public interface TemplateUploader extends Runnable{
/**

View File

@ -26,7 +26,6 @@ import com.cloud.agent.api.storage.Proxy;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Volume;
public class DownloadCommand extends AbstractDownloadCommand implements InternalIdentity {
@ -53,29 +52,29 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal
public DownloadCommand(DownloadCommand that) {
super(that);
this.hvm = that.hvm;
this.checksum = that.checksum;
this.id = that.id;
this.description = that.description;
this.auth = that.getAuth();
this.setSecUrl(that.getSecUrl());
this.maxDownloadSizeInBytes = that.getMaxDownloadSizeInBytes();
this.resourceType = that.resourceType;
this.installPath = that.installPath;
this._store = that._store;
hvm = that.hvm;
checksum = that.checksum;
id = that.id;
description = that.description;
auth = that.getAuth();
setSecUrl(that.getSecUrl());
maxDownloadSizeInBytes = that.getMaxDownloadSizeInBytes();
resourceType = that.resourceType;
installPath = that.installPath;
_store = that._store;
}
public DownloadCommand(TemplateObjectTO template, Long maxDownloadSizeInBytes) {
super(template.getName(), template.getOrigUrl(), template.getFormat(), template.getAccountId());
this._store = template.getDataStore();
this.installPath = template.getPath();
this.hvm = template.isRequiresHvm();
this.checksum = template.getChecksum();
this.id = template.getId();
this.description = template.getDescription();
_store = template.getDataStore();
installPath = template.getPath();
hvm = template.isRequiresHvm();
checksum = template.getChecksum();
id = template.getId();
description = template.getDescription();
if (_store instanceof NfsTO) {
this.setSecUrl(((NfsTO) _store).getUrl());
setSecUrl(((NfsTO) _store).getUrl());
}
this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
}
@ -87,12 +86,12 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal
public DownloadCommand(VolumeObjectTO volume, Long maxDownloadSizeInBytes, String checkSum, String url, ImageFormat format) {
super(volume.getName(), url, format, volume.getAccountId());
this.checksum = checkSum;
this.id = volume.getVolumeId();
this.installPath = volume.getPath();
this._store = volume.getDataStore();
checksum = checkSum;
id = volume.getVolumeId();
installPath = volume.getPath();
_store = volume.getDataStore();
this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
this.resourceType = ResourceType.VOLUME;
resourceType = ResourceType.VOLUME;
}
@Override
public long getId() {
@ -184,6 +183,6 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal
}
public DataStoreTO getCacheStore() {
return this.cacheStore;
return cacheStore;
}
}

View File

@ -27,7 +27,6 @@ import java.util.Date;
import org.junit.Test;
import com.cloud.agent.api.BackupSnapshotCommand;
import com.cloud.agent.api.to.StorageFilerTO;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.StoragePool;