removed import of componentlocator and inject from all files

This commit is contained in:
Alex Huang 2013-01-10 11:44:47 -08:00
parent 395de6f2b3
commit 56e5fbdee2
157 changed files with 2856 additions and 3431 deletions

View File

@ -141,7 +141,7 @@ public abstract class BaseCmd {
public static QueryService _queryService;
static void setComponents(ResponseGenerator generator) {
public static void setComponents(ResponseGenerator generator) {
_mgr = ComponentContext.getComponent(ManagementService.class);
_accountService = ComponentContext.getComponent(AccountService.class);
_configService = ComponentContext.getComponent(ConfigurationService.class);

View File

@ -21,6 +21,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@ -46,15 +47,13 @@ import com.cloud.storage.resource.SecondaryStorageResource;
import com.cloud.storage.template.TemplateUploader.Status;
import com.cloud.storage.template.TemplateUploader.UploadCompleteCallback;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
public class UploadManagerImpl implements UploadManager {
public class Completion implements UploadCompleteCallback {
public class Completion implements UploadCompleteCallback {
private final String jobId;
public Completion(String jobId) {
@ -67,125 +66,125 @@ public class UploadManagerImpl implements UploadManager {
}
}
private static class UploadJob {
private final TemplateUploader tu;
private final String jobId;
private final String name;
private final ImageFormat format;
private String tmpltPath;
private String description;
private String checksum;
private Long accountId;
private String installPathPrefix;
private long templatesize;
private long id;
private static class UploadJob {
private final TemplateUploader tu;
private final String jobId;
private final String name;
private final ImageFormat format;
private String tmpltPath;
private String description;
private String checksum;
private Long accountId;
private String installPathPrefix;
private long templatesize;
private long id;
public UploadJob(TemplateUploader tu, String jobId, long id, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum, String installPathPrefix) {
super();
this.tu = tu;
this.jobId = jobId;
this.name = name;
this.format = format;
this.accountId = accountId;
this.description = descr;
this.checksum = cksum;
this.installPathPrefix = installPathPrefix;
this.templatesize = 0;
this.id = id;
}
public UploadJob(TemplateUploader tu, String jobId, long id, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum, String installPathPrefix) {
super();
this.tu = tu;
this.jobId = jobId;
this.name = name;
this.format = format;
this.accountId = accountId;
this.description = descr;
this.checksum = cksum;
this.installPathPrefix = installPathPrefix;
this.templatesize = 0;
this.id = id;
}
public TemplateUploader getTd() {
return tu;
}
public TemplateUploader getTd() {
return tu;
}
public String getDescription() {
return description;
}
public String getDescription() {
return description;
}
public String getChecksum() {
return checksum;
}
public String getChecksum() {
return checksum;
}
public UploadJob(TemplateUploader td, String jobId, UploadCommand cmd) {
this.tu = td;
this.jobId = jobId;
this.name = cmd.getName();
this.format = cmd.getFormat();
}
public UploadJob(TemplateUploader td, String jobId, UploadCommand cmd) {
this.tu = td;
this.jobId = jobId;
this.name = cmd.getName();
this.format = cmd.getFormat();
}
public TemplateUploader getTemplateUploader() {
return tu;
}
public TemplateUploader getTemplateUploader() {
return tu;
}
public String getJobId() {
return jobId;
}
public String getJobId() {
return jobId;
}
public String getTmpltName() {
return name;
}
public String getTmpltName() {
return name;
}
public ImageFormat getFormat() {
return format;
}
public ImageFormat getFormat() {
return format;
}
public Long getAccountId() {
return accountId;
}
public Long getAccountId() {
return accountId;
}
public long getId() {
return id;
}
public long getId() {
return id;
}
public void setTmpltPath(String tmpltPath) {
this.tmpltPath = tmpltPath;
}
public void setTmpltPath(String tmpltPath) {
this.tmpltPath = tmpltPath;
}
public String getTmpltPath() {
return tmpltPath;
}
public String getTmpltPath() {
return tmpltPath;
}
public String getInstallPathPrefix() {
return installPathPrefix;
}
public String getInstallPathPrefix() {
return installPathPrefix;
}
public void cleanup() {
if (tu != null) {
String upldPath = tu.getUploadLocalPath();
if (upldPath != null) {
File f = new File(upldPath);
f.delete();
}
}
}
public void cleanup() {
if (tu != null) {
String upldPath = tu.getUploadLocalPath();
if (upldPath != null) {
File f = new File(upldPath);
f.delete();
}
}
}
public void setTemplatesize(long templatesize) {
this.templatesize = templatesize;
}
public void setTemplatesize(long templatesize) {
this.templatesize = templatesize;
}
public long getTemplatesize() {
return templatesize;
}
}
public static final Logger s_logger = Logger.getLogger(UploadManagerImpl.class);
private ExecutorService threadPool;
private final Map<String, UploadJob> jobs = new ConcurrentHashMap<String, UploadJob>();
private String parentDir;
private Adapters<Processor> _processors;
private String publicTemplateRepo;
private String extractMountPoint = "/mnt/SecStorage/extractmnt";
private StorageLayer _storage;
private int installTimeoutPerGig;
private boolean _sslCopy;
private String _name;
private boolean hvm;
public long getTemplatesize() {
return templatesize;
}
}
public static final Logger s_logger = Logger.getLogger(UploadManagerImpl.class);
private ExecutorService threadPool;
private final Map<String, UploadJob> jobs = new ConcurrentHashMap<String, UploadJob>();
private String parentDir;
private List<Processor> _processors;
private String publicTemplateRepo;
private final String extractMountPoint = "/mnt/SecStorage/extractmnt";
private StorageLayer _storage;
private int installTimeoutPerGig;
private boolean _sslCopy;
private String _name;
private boolean hvm;
@Override
public String uploadPublicTemplate(long id, String url, String name,
ImageFormat format, Long accountId, String descr,
String cksum, String installPathPrefix, String userName,
String passwd, long templateSizeInBytes) {
@Override
public String uploadPublicTemplate(long id, String url, String name,
ImageFormat format, Long accountId, String descr,
String cksum, String installPathPrefix, String userName,
String passwd, long templateSizeInBytes) {
UUID uuid = UUID.randomUUID();
String jobId = uuid.toString();
@ -194,52 +193,52 @@ public class UploadManagerImpl implements UploadManager {
s_logger.debug("Starting upload from " + completePath);
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
s_logger.error("URI is incorrect: " + url);
throw new CloudRuntimeException("URI is incorrect: " + url);
}
TemplateUploader tu;
if ((uri != null) && (uri.getScheme() != null)) {
if (uri.getScheme().equalsIgnoreCase("ftp")) {
tu = new FtpTemplateUploader(completePath, url, new Completion(jobId), templateSizeInBytes);
} else {
s_logger.error("Scheme is not supported " + url);
throw new CloudRuntimeException("Scheme is not supported " + url);
}
} else {
s_logger.error("Unable to download from URL: " + url);
throw new CloudRuntimeException("Unable to download from URL: " + url);
}
UploadJob uj = new UploadJob(tu, jobId, id, name, format, hvm, accountId, descr, cksum, installPathPrefix);
jobs.put(jobId, uj);
threadPool.execute(tu);
try {
uri = new URI(url);
} catch (URISyntaxException e) {
s_logger.error("URI is incorrect: " + url);
throw new CloudRuntimeException("URI is incorrect: " + url);
}
TemplateUploader tu;
if ((uri != null) && (uri.getScheme() != null)) {
if (uri.getScheme().equalsIgnoreCase("ftp")) {
tu = new FtpTemplateUploader(completePath, url, new Completion(jobId), templateSizeInBytes);
} else {
s_logger.error("Scheme is not supported " + url);
throw new CloudRuntimeException("Scheme is not supported " + url);
}
} else {
s_logger.error("Unable to download from URL: " + url);
throw new CloudRuntimeException("Unable to download from URL: " + url);
}
UploadJob uj = new UploadJob(tu, jobId, id, name, format, hvm, accountId, descr, cksum, installPathPrefix);
jobs.put(jobId, uj);
threadPool.execute(tu);
return jobId;
return jobId;
}
}
@Override
public String getUploadError(String jobId) {
@Override
public String getUploadError(String jobId) {
UploadJob uj = jobs.get(jobId);
if (uj != null) {
return uj.getTemplateUploader().getUploadError();
}
return null;
}
}
@Override
public int getUploadPct(String jobId) {
UploadJob uj = jobs.get(jobId);
@Override
public int getUploadPct(String jobId) {
UploadJob uj = jobs.get(jobId);
if (uj != null) {
return uj.getTemplateUploader().getUploadPercent();
}
return 0;
}
}
@Override
public Status getUploadStatus(String jobId) {
@Override
public Status getUploadStatus(String jobId) {
UploadJob job = jobs.get(jobId);
if (job != null) {
TemplateUploader tu = job.getTemplateUploader();
@ -248,7 +247,7 @@ public class UploadManagerImpl implements UploadManager {
}
}
return Status.UNKNOWN;
}
}
public static UploadVO.Status convertStatus(Status tds) {
switch (tds) {
@ -277,11 +276,11 @@ public class UploadManagerImpl implements UploadManager {
public com.cloud.storage.UploadVO.Status getUploadStatus2(String jobId) {
return convertStatus(getUploadStatus(jobId));
}
@Override
public String getPublicTemplateRepo() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getPublicTemplateRepo() {
// TODO Auto-generated method stub
return null;
}
private UploadAnswer handleUploadProgressCmd(UploadProgressCommand cmd) {
String jobId = cmd.getJobId();
@ -290,7 +289,7 @@ public class UploadManagerImpl implements UploadManager {
if (jobId != null)
uj = jobs.get(jobId);
if (uj == null) {
return new UploadAnswer(null, 0, "Cannot find job", com.cloud.storage.UploadVO.Status.UNKNOWN, "", "", 0);
return new UploadAnswer(null, 0, "Cannot find job", com.cloud.storage.UploadVO.Status.UNKNOWN, "", "", 0);
}
TemplateUploader td = uj.getTemplateUploader();
switch (cmd.getRequest()) {
@ -300,7 +299,7 @@ public class UploadManagerImpl implements UploadManager {
td.stopUpload();
sleep();
break;
/*case RESTART:
/*case RESTART:
td.stopUpload();
sleep();
threadPool.execute(td);
@ -319,7 +318,7 @@ public class UploadManagerImpl implements UploadManager {
@Override
public UploadAnswer handleUploadCommand(SecondaryStorageResource resource, UploadCommand cmd) {
s_logger.warn("Handling the upload " +cmd.getInstallPath() + " " + cmd.getId());
s_logger.warn("Handling the upload " +cmd.getInstallPath() + " " + cmd.getId());
if (cmd instanceof UploadProgressCommand) {
return handleUploadProgressCmd((UploadProgressCommand) cmd);
}
@ -327,9 +326,9 @@ public class UploadManagerImpl implements UploadManager {
String user = null;
String password = null;
String jobId = uploadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(),
cmd.getFormat(), cmd.getAccountId(), cmd.getDescription(),
cmd.getChecksum(), cmd.getInstallPath(), user, password,
cmd.getTemplateSizeInBytes());
cmd.getFormat(), cmd.getAccountId(), cmd.getDescription(),
cmd.getChecksum(), cmd.getInstallPath(), user, password,
cmd.getTemplateSizeInBytes());
sleep();
if (jobId == null) {
return new UploadAnswer(null, 0, "Internal Error", com.cloud.storage.UploadVO.Status.UPLOAD_ERROR, "", "", 0);
@ -341,14 +340,14 @@ public class UploadManagerImpl implements UploadManager {
@Override
public CreateEntityDownloadURLAnswer handleCreateEntityURLCommand(CreateEntityDownloadURLCommand cmd){
boolean isApacheUp = checkAndStartApache();
if (!isApacheUp){
String errorString = "Error in starting Apache server ";
boolean isApacheUp = checkAndStartApache();
if (!isApacheUp){
String errorString = "Error in starting Apache server ";
s_logger.error(errorString);
return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
}
}
// Create the directory structure so that its visible under apache server root
String extractDir = "/var/www/html/userdata/";
String extractDir = "/var/www/html/userdata/";
Script command = new Script("mkdir", s_logger);
command.add("-p");
command.add(extractDir);
@ -361,14 +360,14 @@ public class UploadManagerImpl implements UploadManager {
// Create a random file under the directory for security reasons.
String uuid = cmd.getExtractLinkUUID();
command = new Script("touch", s_logger);
command.add(extractDir + uuid);
result = command.execute();
if (result != null) {
String errorString = "Error in creating file " +uuid+ " ,error: " + result;
s_logger.warn(errorString);
return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
}
command = new Script("touch", s_logger);
command.add(extractDir + uuid);
result = command.execute();
if (result != null) {
String errorString = "Error in creating file " +uuid+ " ,error: " + result;
s_logger.warn(errorString);
return new CreateEntityDownloadURLAnswer(errorString, CreateEntityDownloadURLAnswer.RESULT_FAILURE);
}
// Create a symbolic link from the actual directory to the template location. The entity would be directly visible under /var/www/html/userdata/cmd.getInstallPath();
@ -395,7 +394,7 @@ public class UploadManagerImpl implements UploadManager {
Script command = new Script("/bin/bash", s_logger);
command.add("-c");
//We just need to remove the UUID.vhd
//We just need to remove the UUID.vhd
String extractUrl = cmd.getExtractUrl();
command.add("unlink /var/www/html/userdata/" +extractUrl.substring(extractUrl.lastIndexOf(File.separator) + 1));
String result = command.execute();
@ -422,27 +421,27 @@ public class UploadManagerImpl implements UploadManager {
return new DeleteEntityDownloadURLAnswer("", CreateEntityDownloadURLAnswer.RESULT_SUCCESS);
}
private String getInstallPath(String jobId) {
// TODO Auto-generated method stub
return null;
}
private String getInstallPath(String jobId) {
// TODO Auto-generated method stub
return null;
}
private String getUploadLocalPath(String jobId) {
// TODO Auto-generated method stub
return null;
}
private String getUploadLocalPath(String jobId) {
// TODO Auto-generated method stub
return null;
}
private long getUploadTemplateSize(String jobId){
UploadJob uj = jobs.get(jobId);
private long getUploadTemplateSize(String jobId){
UploadJob uj = jobs.get(jobId);
if (uj != null) {
return uj.getTemplatesize();
}
return 0;
}
}
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
_name = name;
String value = null;
@ -457,21 +456,25 @@ public class UploadManagerImpl implements UploadManager {
Class<StorageLayer> clazz;
try {
clazz = (Class<StorageLayer>) Class.forName(value);
_storage = clazz.newInstance();
} catch (ClassNotFoundException e) {
throw new ConfigurationException("Unable to instantiate " + value);
} catch (InstantiationException e) {
throw new ConfigurationException("Unable to instantiate " + value);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Unable to instantiate " + value);
}
_storage = ComponentLocator.inject(clazz);
}
String useSsl = (String)params.get("sslcopy");
if (useSsl != null) {
_sslCopy = Boolean.parseBoolean(useSsl);
_sslCopy = Boolean.parseBoolean(useSsl);
}
String inSystemVM = (String)params.get("secondary.storage.vm");
if (inSystemVM != null && "true".equalsIgnoreCase(inSystemVM)) {
s_logger.info("UploadManager: starting additional services since we are inside system vm");
startAdditionalServices();
//blockOutgoingOnPrivate();
s_logger.info("UploadManager: starting additional services since we are inside system vm");
startAdditionalServices();
//blockOutgoingOnPrivate();
}
value = (String) params.get("install.timeout.pergig");
@ -489,53 +492,53 @@ public class UploadManagerImpl implements UploadManager {
threadPool = Executors.newFixedThreadPool(numInstallThreads);
return true;
}
}
private void startAdditionalServices() {
private void startAdditionalServices() {
Script command = new Script("rm", s_logger);
command.add("-rf");
command.add(extractMountPoint);
String result = command.execute();
if (result != null) {
s_logger.warn("Error in creating file " +extractMountPoint+ " ,error: " + result );
return;
}
Script command = new Script("rm", s_logger);
command.add("-rf");
command.add(extractMountPoint);
String result = command.execute();
if (result != null) {
s_logger.warn("Error in creating file " +extractMountPoint+ " ,error: " + result );
return;
}
command = new Script("touch", s_logger);
command.add(extractMountPoint);
result = command.execute();
if (result != null) {
s_logger.warn("Error in creating file " +extractMountPoint+ " ,error: " + result );
return;
}
command = new Script("touch", s_logger);
command.add(extractMountPoint);
result = command.execute();
if (result != null) {
s_logger.warn("Error in creating file " +extractMountPoint+ " ,error: " + result );
return;
}
command = new Script("/bin/bash", s_logger);
command.add("-c");
command.add("ln -sf " + parentDir + " " +extractMountPoint);
result = command.execute();
if (result != null) {
s_logger.warn("Error in linking err=" + result );
return;
}
command = new Script("/bin/bash", s_logger);
command.add("-c");
command.add("ln -sf " + parentDir + " " +extractMountPoint);
result = command.execute();
if (result != null) {
s_logger.warn("Error in linking err=" + result );
return;
}
}
}
@Override
public String getName() {
return _name;
}
@Override
public String getName() {
return _name;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public boolean stop() {
return true;
}
/**
* Get notified of change of job status. Executed in context of uploader thread
@ -582,7 +585,7 @@ public class UploadManagerImpl implements UploadManager {
tu.setStatus(Status.UNRECOVERABLE_ERROR);
tu.setUploadError("Failed post upload script: " + result);
} else {
s_logger.warn("Upload completed successfully at " + new SimpleDateFormat().format(new Date()));
s_logger.warn("Upload completed successfully at " + new SimpleDateFormat().format(new Date()));
tu.setStatus(Status.POST_UPLOAD_FINISHED);
tu.setUploadError("Upload completed successfully at " + new SimpleDateFormat().format(new Date()));
}
@ -596,9 +599,9 @@ public class UploadManagerImpl implements UploadManager {
}
}
private String postUpload(String jobId) {
return null;
}
private String postUpload(String jobId) {
return null;
}
private void sleep() {
try {
@ -608,18 +611,18 @@ public class UploadManagerImpl implements UploadManager {
}
}
private boolean checkAndStartApache() {
private boolean checkAndStartApache() {
//Check whether the Apache server is running
Script command = new Script("/bin/bash", s_logger);
command.add("-c");
command.add("if [ -d /etc/apache2 ] ; then service apache2 status | grep pid; else service httpd status | grep pid; fi ");
String result = command.execute();
//Check whether the Apache server is running
Script command = new Script("/bin/bash", s_logger);
command.add("-c");
command.add("if [ -d /etc/apache2 ] ; then service apache2 status | grep pid; else service httpd status | grep pid; fi ");
String result = command.execute();
//Apache Server is not running. Try to start it.
if (result != null) {
//Apache Server is not running. Try to start it.
if (result != null) {
/*s_logger.warn("Apache server not running, trying to start it");
/*s_logger.warn("Apache server not running, trying to start it");
String port = Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
String intf = TemplateConstants.DEFAULT_TMPLT_COPY_INTF;
@ -643,16 +646,16 @@ public class UploadManagerImpl implements UploadManager {
return false;
}*/
command = new Script("/bin/bash", s_logger);
command.add("-c");
command.add("if [ -d /etc/apache2 ] ; then service apache2 start; else service httpd start; fi ");
result = command.execute();
if (result != null) {
s_logger.warn("Error in starting httpd service err=" + result );
return false;
}
}
command = new Script("/bin/bash", s_logger);
command.add("-c");
command.add("if [ -d /etc/apache2 ] ; then service apache2 start; else service httpd start; fi ");
result = command.execute();
if (result != null) {
s_logger.warn("Error in starting httpd service err=" + result );
return false;
}
}
return true;
}
return true;
}
}

View File

@ -8,7 +8,7 @@ import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
import org.apache.cloudstack.storage.volume.ObjectInDataStoreStateMachine.Event;
import org.springframework.stereotype.Component;
import com.cloud.utils.component.Inject;
@Component
public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager {

View File

@ -38,7 +38,7 @@ import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Volume;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;

View File

@ -29,7 +29,7 @@ import com.cloud.exception.InvalidParameterValueException;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.AssociateLunCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "associateLun", description="Associate a LUN with a guest IQN", responseObject = AssociateLunCmdResponse.class)
public class AssociateLunCmd extends BaseCmd {

View File

@ -33,7 +33,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.CreateLunCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "createLunOnFiler", description="Create a LUN from a pool", responseObject = CreateLunCmdResponse.class)
public class CreateLunCmd extends BaseCmd {

View File

@ -32,7 +32,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.CreateVolumeOnFilerCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "createVolumeOnFiler", description="Create a volume", responseObject = CreateVolumeOnFilerCmdResponse.class)
public class CreateVolumeOnFilerCmd extends BaseCmd {

View File

@ -31,7 +31,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.CreateVolumePoolCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "createPool", description="Create a pool", responseObject = CreateVolumePoolCmdResponse.class)
public class CreateVolumePoolCmd extends BaseCmd {

View File

@ -33,7 +33,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.DeleteVolumePoolCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "deletePool", description="Delete a pool", responseObject = DeleteVolumePoolCmdResponse.class)
public class DeleteVolumePoolCmd extends BaseCmd {

View File

@ -33,7 +33,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.DeleteLUNCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "destroyLunOnFiler", description="Destroy a LUN", responseObject = DeleteLUNCmdResponse.class)
public class DestroyLunCmd extends BaseCmd {

View File

@ -31,7 +31,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.DeleteVolumeOnFilerCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "destroyVolumeOnFiler", description="Destroy a Volume", responseObject = DeleteVolumeOnFilerCmdResponse.class)
public class DestroyVolumeOnFilerCmd extends BaseCmd {

View File

@ -30,7 +30,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.DissociateLunCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "dissociateLun", description="Dissociate a LUN", responseObject = DissociateLunCmdResponse.class)
public class DissociateLunCmd extends BaseCmd {

View File

@ -36,7 +36,7 @@ import com.cloud.netapp.LunVO;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.ListLunsCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "listLunsOnFiler", description="List LUN", responseObject = ListLunsCmdResponse.class)
public class ListLunsCmd extends BaseCmd

View File

@ -34,7 +34,7 @@ import com.cloud.netapp.NetappManager;
import com.cloud.netapp.PoolVO;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.ListVolumePoolsCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "listPools", description="List Pool", responseObject = ListVolumePoolsCmdResponse.class)
public class ListVolumePoolsCmd extends BaseCmd {

View File

@ -33,7 +33,7 @@ import com.cloud.netapp.NetappManager;
import com.cloud.netapp.NetappVolumeVO;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.ListVolumesOnFilerCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "listVolumesOnFiler", description="List Volumes", responseObject = ListVolumesOnFilerCmdResponse.class)
public class ListVolumesOnFilerCmd extends BaseCmd {

View File

@ -31,7 +31,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.netapp.NetappManager;
import com.cloud.server.ManagementService;
import com.cloud.server.api.response.netapp.ModifyVolumePoolCmdResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "modifyPool", description="Modify pool", responseObject = ModifyVolumePoolCmdResponse.class)
public class ModifyVolumePoolCmd extends BaseCmd {

View File

@ -36,7 +36,6 @@ import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.offering.ServiceOffering;
import com.cloud.resource.ResourceManager;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@ -56,14 +55,14 @@ public class RandomAllocator implements HostAllocator {
@Override
public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type,
ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) {
ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) {
long dcId = plan.getDataCenterId();
Long podId = plan.getPodId();
Long clusterId = plan.getClusterId();
ServiceOffering offering = vmProfile.getServiceOffering();
long dcId = plan.getDataCenterId();
Long podId = plan.getPodId();
Long clusterId = plan.getClusterId();
ServiceOffering offering = vmProfile.getServiceOffering();
List<Host> suitableHosts = new ArrayList<Host>();
List<Host> suitableHosts = new ArrayList<Host>();
if (type == Host.Type.Storage) {
return suitableHosts;
@ -71,17 +70,17 @@ public class RandomAllocator implements HostAllocator {
String hostTag = offering.getHostTag();
if(hostTag != null){
s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId + " having host tag:" + hostTag);
s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId + " having host tag:" + hostTag);
}else{
s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
}
// list all computing hosts, regardless of whether they support routing...it's random after all
List<? extends Host> hosts = new ArrayList<HostVO>();
if(hostTag != null){
hosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag);
hosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag);
}else{
hosts = _resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId);
hosts = _resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId);
}
s_logger.debug("Random Allocator found " + hosts.size() + " hosts");
@ -93,12 +92,12 @@ public class RandomAllocator implements HostAllocator {
Collections.shuffle(hosts);
for (Host host : hosts) {
if(suitableHosts.size() == returnUpTo){
break;
}
if(suitableHosts.size() == returnUpTo){
break;
}
if (!avoid.shouldAvoid(host)) {
suitableHosts.add(host);
suitableHosts.add(host);
}else{
if (s_logger.isDebugEnabled()) {
s_logger.debug("Host name: " + host.getName() + ", hostId: "+ host.getId() +" is in avoid set, skipping this and trying other available hosts");

View File

@ -212,7 +212,7 @@ import com.cloud.storage.template.TemplateLocation;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.OutputInterpreter;

View File

@ -58,7 +58,7 @@ import com.cloud.simulator.MockVMVO;
import com.cloud.simulator.dao.MockHostDao;
import com.cloud.simulator.dao.MockVMDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Inject;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;

View File

@ -77,7 +77,7 @@ import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.template.TemplateInfo;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.DiskProfile;

View File

@ -46,7 +46,7 @@ import com.cloud.simulator.dao.MockSecurityRulesDao;
import com.cloud.simulator.dao.MockVMDao;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine.State;

View File

@ -28,7 +28,7 @@ import com.cloud.simulator.MockVMVO;
import com.cloud.simulator.dao.MockConfigurationDao;
import com.cloud.simulator.dao.MockHostDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.ConnectionConcierge;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;

View File

@ -31,7 +31,7 @@ import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.server.ManagementService;
import com.cloud.user.Account;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "configureSimulator", description="configure simulator", responseObject=SuccessResponse.class)
public class ConfigureSimulator extends BaseCmd {

View File

@ -43,7 +43,7 @@ import com.cloud.agent.manager.SimulatorManager.AgentType;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.simulator.MockHost;
import com.cloud.utils.component.ComponentLocator;
public class AgentResourceBase implements ServerResource {
private static final Logger s_logger = Logger

View File

@ -54,7 +54,7 @@ import com.cloud.storage.VMTemplateZoneVO;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateHostDao;
import com.cloud.storage.dao.VMTemplateZoneDao;
import com.cloud.utils.component.Inject;
@Local(value = Discoverer.class)
public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {

View File

@ -38,7 +38,7 @@ import com.cloud.host.Status;
import com.cloud.storage.SnapshotVO;
import com.cloud.storage.dao.SnapshotDao;
import com.cloud.storage.secondary.SecondaryStorageDiscoverer;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.log4j.Logger;

View File

@ -24,7 +24,7 @@ import com.cloud.hypervisor.HypervisorGuruBase;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.GuestOSVO;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.utils.component.Inject;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;

View File

@ -25,7 +25,7 @@ import javax.naming.ConfigurationException;
import com.cloud.simulator.MockHostVO;
import com.cloud.simulator.MockVMVO;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder;

View File

@ -66,7 +66,7 @@ import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.user.Account;
import com.cloud.utils.UriUtils;
import com.cloud.utils.component.ComponentLocator;
import com.vmware.vim25.ClusterDasConfigInfo;
import com.vmware.vim25.ManagedObjectReference;

View File

@ -86,7 +86,7 @@ import com.cloud.storage.secondary.SecondaryStorageVmManager;
import com.cloud.utils.FileUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;

View File

@ -21,7 +21,7 @@ import org.apache.log4j.Logger;
import com.cloud.hypervisor.vmware.manager.VmwareManager;
import com.cloud.hypervisor.vmware.util.VmwareContext;
import com.cloud.utils.StringUtils;
import com.cloud.utils.component.ComponentLocator;
import com.vmware.apputils.version.ExtendedAppUtil;
public class VmwareContextFactory {

View File

@ -200,7 +200,7 @@ import com.cloud.storage.template.TemplateInfo;
import com.cloud.utils.DateUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.exception.ExceptionUtil;

View File

@ -30,7 +30,7 @@ import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.dao.LoadBalancerDaoImpl;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.JoinBuilder.JoinType;
import com.cloud.utils.db.SearchBuilder;

View File

@ -30,7 +30,7 @@ import org.springframework.stereotype.Component;
import com.cloud.server.ManagementServer;
import com.cloud.user.UserAccount;
import com.cloud.user.dao.UserAccountDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
/**

View File

@ -30,7 +30,7 @@ import org.springframework.stereotype.Component;
import com.cloud.server.ManagementServer;
import com.cloud.user.UserAccount;
import com.cloud.user.dao.UserAccountDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;

View File

@ -32,8 +32,8 @@ import com.cloud.server.ManagementServer;
import com.cloud.servlet.CloudStartupServlet;
import com.cloud.user.UserAccount;
import com.cloud.user.dao.UserAccountDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
@Local(value={UserAuthenticator.class})

View File

@ -66,7 +66,6 @@ import com.cloud.agent.transport.Response;
import com.cloud.alert.AlertManager;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.cluster.ManagementServerNode;
import com.cloud.cluster.StackMaid;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.ClusterDetailsDao;
@ -977,8 +976,6 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
}
} catch (final Exception e) {
s_logger.error("Exception caught while handling disconnect: ", e);
} finally {
StackMaid.current().exitCleanup();
}
}
}
@ -1150,7 +1147,6 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
if (actionDelegate != null) {
actionDelegate.action(new Long(id));
}
StackMaid.current().exitCleanup();
}
}
}
@ -1381,7 +1377,6 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
}
}
} finally {
StackMaid.current().exitCleanup();
txn.close();
}
}

View File

@ -62,7 +62,6 @@ import com.cloud.cluster.ClusterManagerListener;
import com.cloud.cluster.ClusteredAgentRebalanceService;
import com.cloud.cluster.ManagementServerHost;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.StackMaid;
import com.cloud.cluster.agentlb.AgentLoadBalancerPlanner;
import com.cloud.cluster.agentlb.HostTransferMapVO;
import com.cloud.cluster.agentlb.HostTransferMapVO.HostTransferState;
@ -1120,8 +1119,6 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
rebalanceHost(hostId, currentOwnerId, futureOwnerId);
} catch (Exception e) {
s_logger.warn("Unable to rebalance host id=" + hostId, e);
} finally {
StackMaid.current().exitCleanup();
}
}
}

View File

@ -104,12 +104,12 @@ import org.apache.http.protocol.ResponseContent;
import org.apache.http.protocol.ResponseDate;
import org.apache.http.protocol.ResponseServer;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.response.ApiResponseSerializer;
import com.cloud.async.AsyncJob;
import com.cloud.async.AsyncJobManager;
import com.cloud.async.AsyncJobVO;
import com.cloud.cluster.StackMaid;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationVO;
import com.cloud.configuration.dao.ConfigurationDao;
@ -136,19 +136,20 @@ import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CSExceptionErrorCode;
import com.cloud.uuididentity.dao.IdentityDao;
@Component
public class ApiServer implements HttpRequestHandler {
private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
private static final Logger s_accessLogger = Logger.getLogger("apiserver." + ApiServer.class.getName());
public static boolean encodeApiResponse = false;
public static String jsonContentType = "text/javascript";
private ApiDispatcher _dispatcher;
@Inject ApiDispatcher _dispatcher;
@Inject private final AccountManager _accountMgr = null;
@Inject private final DomainManager _domainMgr = null;
@Inject private final AsyncJobManager _asyncMgr = null;
@Inject private ConfigurationDao _configDao;
@Inject protected List<APIAccessChecker> _apiAccessCheckers;
@Inject AccountManager _accountMgr;
@Inject DomainManager _domainMgr;
@Inject AsyncJobManager _asyncMgr;
@Inject ConfigurationDao _configDao;
@Inject List<APIAccessChecker> _apiAccessCheckers;
@Inject List<PluggableService> _pluggableServices;
@Inject IdentityDao _identityDao;
@ -190,7 +191,6 @@ public class ApiServer implements HttpRequestHandler {
_systemAccount = _accountMgr.getSystemAccount();
_systemUser = _accountMgr.getSystemUser();
_dispatcher = ApiDispatcher.getInstance();
Integer apiPort = null; // api port, null by default
SearchCriteria<ConfigurationVO> sc = _configDao.createSearchCriteria();
@ -907,12 +907,8 @@ public class ApiServer implements HttpRequestHandler {
HttpContext context = new BasicHttpContext(null);
try {
while (!Thread.interrupted() && _conn.isOpen()) {
try {
_httpService.handleRequest(_conn, context);
_conn.close();
} finally {
StackMaid.current().exitCleanup();
}
_httpService.handleRequest(_conn, context);
_conn.close();
}
} catch (ConnectionClosedException ex) {
if (s_logger.isTraceEnabled()) {

View File

@ -23,6 +23,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -32,14 +33,11 @@ import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.log4j.Logger;
import com.cloud.cluster.StackMaid;
import com.cloud.exception.CloudAuthenticationException;
import com.cloud.server.ManagementServer;
import com.cloud.user.Account;
import com.cloud.user.AccountService;
import com.cloud.user.UserContext;
import com.cloud.utils.StringUtils;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
@SuppressWarnings("serial")
@ -47,8 +45,8 @@ public class ApiServlet extends HttpServlet {
public static final Logger s_logger = Logger.getLogger(ApiServlet.class.getName());
private static final Logger s_accessLogger = Logger.getLogger("apiserver." + ApiServer.class.getName());
private ApiServer _apiServer = null;
private AccountService _accountMgr = null;
ApiServer _apiServer;
@Inject AccountService _accountMgr;
public ApiServlet() {
super();
@ -56,26 +54,16 @@ public class ApiServlet extends HttpServlet {
if (_apiServer == null) {
throw new CloudRuntimeException("ApiServer not initialized");
}
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
_accountMgr = locator.getManager(AccountService.class);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
try {
processRequest(req, resp);
} finally {
StackMaid.current().exitCleanup();
}
processRequest(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
try {
processRequest(req, resp);
} finally {
StackMaid.current().exitCleanup();
}
processRequest(req, resp);
}
private void utf8Fixup(HttpServletRequest req, Map<String, Object[]> params) {
@ -305,7 +293,7 @@ public class ApiServlet extends HttpServlet {
auditTrailSb.insert(0,
"(userId=" + UserContext.current().getCallerUserId() + " accountId=" + UserContext.current().getCaller().getId() + " sessionId=" + (session != null ? session.getId() : null)
+ ")");
+ ")");
try {
String response = _apiServer.handleRequest(params, false, responseType, auditTrailSb);

View File

@ -16,91 +16,93 @@
// under the License.
package com.cloud.api.commands;
import org.apache.cloudstack.api.*;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.TrafficMonitorResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.host.Host;
import com.cloud.network.NetworkUsageManager;
import com.cloud.server.ManagementService;
import org.apache.cloudstack.api.response.TrafficMonitorResponse;
import com.cloud.user.Account;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "addTrafficMonitor", description="Adds Traffic Monitor Host for Direct Network Usage", responseObject = TrafficMonitorResponse.class)
public class AddTrafficMonitorCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(AddTrafficMonitorCmd.class.getName());
private static final String s_name = "addtrafficmonitorresponse";
public static final Logger s_logger = Logger.getLogger(AddTrafficMonitorCmd.class.getName());
private static final String s_name = "addtrafficmonitorresponse";
@Inject NetworkUsageManager networkUsageMgr;
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
required = true, description="Zone in which to add the external firewall appliance.")
private Long zoneId;
private Long zoneId;
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the traffic monitor Host")
private String url;
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the traffic monitor Host")
private String url;
@Parameter(name=ApiConstants.INCL_ZONES, type=CommandType.STRING, description="Traffic going into the listed zones will be metered")
private String inclZones;
@Parameter(name=ApiConstants.INCL_ZONES, type=CommandType.STRING, description="Traffic going into the listed zones will be metered")
private String inclZones;
@Parameter(name=ApiConstants.EXCL_ZONES, type=CommandType.STRING, description="Traffic going into the listed zones will not be metered")
private String exclZones;
@Parameter(name=ApiConstants.EXCL_ZONES, type=CommandType.STRING, description="Traffic going into the listed zones will not be metered")
private String exclZones;
///////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
///////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getInclZones() {
return inclZones;
}
public String getInclZones() {
return inclZones;
}
public String getExclZones() {
return exclZones;
}
public String getExclZones() {
return exclZones;
}
public Long getZoneId() {
return zoneId;
}
public Long getZoneId() {
return zoneId;
}
public String getUrl() {
return url;
}
public String getUrl() {
return url;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public String getCommandName() {
return s_name;
}
@Override
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
@Override
public void execute(){
try {
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
NetworkUsageManager networkUsageMgr = locator.getManager(NetworkUsageManager.class);
Host trafficMonitor = networkUsageMgr.addTrafficMonitor(this);
TrafficMonitorResponse response = networkUsageMgr.getApiResponse(trafficMonitor);
response.setObjectName("trafficmonitor");
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException ipve) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage());
} catch (CloudRuntimeException cre) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage());
}
try {
Host trafficMonitor = networkUsageMgr.addTrafficMonitor(this);
TrafficMonitorResponse response = networkUsageMgr.getApiResponse(trafficMonitor);
response.setObjectName("trafficmonitor");
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException ipve) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage());
} catch (CloudRuntimeException cre) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage());
}
}
}

View File

@ -16,71 +16,70 @@
// under the License.
package com.cloud.api.commands;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.log4j.Logger;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.log4j.Logger;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.NetworkUsageManager;
import com.cloud.server.ManagementService;
import com.cloud.user.Account;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "deleteTrafficMonitor", description="Deletes an traffic monitor host.", responseObject = SuccessResponse.class)
public class DeleteTrafficMonitorCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(DeleteTrafficMonitorCmd.class.getName());
private static final String s_name = "deletetrafficmonitorresponse";
public static final Logger s_logger = Logger.getLogger(DeleteTrafficMonitorCmd.class.getName());
private static final String s_name = "deletetrafficmonitorresponse";
@Inject NetworkUsageManager _networkUsageMgr;
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = HostResponse.class,
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = HostResponse.class,
required = true, description="Id of the Traffic Monitor Host.")
private Long id;
private Long id;
///////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
///////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getId() {
return id;
}
public Long getId() {
return id;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public String getCommandName() {
return s_name;
}
@Override
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
@Override
@Override
public void execute(){
try {
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
NetworkUsageManager _networkUsageMgr = locator.getManager(NetworkUsageManager.class);
boolean result = _networkUsageMgr.deleteTrafficMonitor(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete traffic monitor.");
}
} catch (InvalidParameterValueException e) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to delete traffic monitor.");
}
try {
boolean result = _networkUsageMgr.deleteTrafficMonitor(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete traffic monitor.");
}
} catch (InvalidParameterValueException e) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to delete traffic monitor.");
}
}
}

View File

@ -32,7 +32,7 @@ import com.cloud.host.Host;
import com.cloud.network.NetworkUsageManager;
import com.cloud.server.ManagementService;
import org.apache.cloudstack.api.response.TrafficMonitorResponse;
import com.cloud.utils.component.ComponentLocator;
@APICommand(name = "listTrafficMonitors", description="List traffic monitor Hosts.", responseObject = TrafficMonitorResponse.class)
public class ListTrafficMonitorsCmd extends BaseListCmd {

View File

@ -20,21 +20,19 @@ import java.util.ArrayList;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.NicResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.vo.DomainRouterJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.NicResponse;
import org.springframework.stereotype.Component;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.router.VirtualRouter;
import com.cloud.user.Account;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@ -47,9 +45,9 @@ public class DomainRouterJoinDaoImpl extends GenericDaoBase<DomainRouterJoinVO,
@Inject
private ConfigurationDao _configDao;
private SearchBuilder<DomainRouterJoinVO> vrSearch;
private final SearchBuilder<DomainRouterJoinVO> vrSearch;
private SearchBuilder<DomainRouterJoinVO> vrIdSearch;
private final SearchBuilder<DomainRouterJoinVO> vrIdSearch;
protected DomainRouterJoinDaoImpl() {

View File

@ -25,21 +25,19 @@ import java.util.List;
import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.vo.HostJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.host.Host;
import com.cloud.host.HostStats;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.response.HostResponse;
import org.springframework.stereotype.Component;
import com.cloud.storage.StorageStats;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@ -52,9 +50,9 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
@Inject
private ConfigurationDao _configDao;
private SearchBuilder<HostJoinVO> hostSearch;
private final SearchBuilder<HostJoinVO> hostSearch;
private SearchBuilder<HostJoinVO> hostIdSearch;
private final SearchBuilder<HostJoinVO> hostIdSearch;
protected HostJoinDaoImpl() {
@ -97,14 +95,14 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)
|| details.contains(HostDetails.stats) || details.contains(HostDetails.events)) {
hostResponse.setOsCategoryId(host.getOsCategoryUuid());
hostResponse.setOsCategoryName(host.getOsCategoryName());
hostResponse.setZoneName(host.getZoneName());
hostResponse.setPodName(host.getPodName());
if ( host.getClusterId() > 0) {
hostResponse.setClusterName(host.getClusterName());
hostResponse.setClusterType(host.getClusterType().toString());
}
hostResponse.setOsCategoryId(host.getOsCategoryUuid());
hostResponse.setOsCategoryName(host.getOsCategoryName());
hostResponse.setZoneName(host.getZoneName());
hostResponse.setPodName(host.getPodName());
if ( host.getClusterId() > 0) {
hostResponse.setClusterName(host.getClusterName());
hostResponse.setClusterType(host.getClusterType().toString());
}
}
DecimalFormat decimalFormat = new DecimalFormat("#.##");

View File

@ -20,19 +20,17 @@ import java.util.ArrayList;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.response.ProjectResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.vo.ProjectJoinVO;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import org.apache.cloudstack.api.response.ProjectResponse;
import org.springframework.stereotype.Component;
import com.cloud.projects.Project;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@ -45,9 +43,9 @@ public class ProjectJoinDaoImpl extends GenericDaoBase<ProjectJoinVO, Long> impl
@Inject
private ConfigurationDao _configDao;
private SearchBuilder<ProjectJoinVO> prjSearch;
private final SearchBuilder<ProjectJoinVO> prjSearch;
private SearchBuilder<ProjectJoinVO> prjIdSearch;
private final SearchBuilder<ProjectJoinVO> prjIdSearch;
protected ProjectJoinDaoImpl() {

View File

@ -20,18 +20,16 @@ import java.util.ArrayList;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.springframework.stereotype.Component;
import com.cloud.server.ResourceTag;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@ -44,9 +42,9 @@ public class ResourceTagJoinDaoImpl extends GenericDaoBase<ResourceTagJoinVO, Lo
@Inject
private ConfigurationDao _configDao;
private SearchBuilder<ResourceTagJoinVO> tagSearch;
private final SearchBuilder<ResourceTagJoinVO> tagSearch;
private SearchBuilder<ResourceTagJoinVO> tagIdSearch;
private final SearchBuilder<ResourceTagJoinVO> tagIdSearch;
protected ResourceTagJoinDaoImpl() {

View File

@ -20,23 +20,21 @@ import java.util.ArrayList;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.SecurityGroupRuleResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.SecurityGroupJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.SecurityGroupRuleResponse;
import org.springframework.stereotype.Component;
import com.cloud.network.security.SecurityGroup;
import com.cloud.network.security.SecurityRule.SecurityRuleType;
import com.cloud.user.Account;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@ -49,9 +47,9 @@ public class SecurityGroupJoinDaoImpl extends GenericDaoBase<SecurityGroupJoinVO
@Inject
private ConfigurationDao _configDao;
private SearchBuilder<SecurityGroupJoinVO> sgSearch;
private final SearchBuilder<SecurityGroupJoinVO> sgSearch;
private SearchBuilder<SecurityGroupJoinVO> sgIdSearch;
private final SearchBuilder<SecurityGroupJoinVO> sgIdSearch;
protected SecurityGroupJoinDaoImpl() {

View File

@ -18,19 +18,19 @@ package com.cloud.api.query.dao;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Local;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.vo.StoragePoolJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.springframework.stereotype.Component;
import com.cloud.storage.StoragePool;
import com.cloud.storage.StorageStats;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@ -44,9 +44,9 @@ public class StoragePoolJoinDaoImpl extends GenericDaoBase<StoragePoolJoinVO, Lo
@Inject
private ConfigurationDao _configDao;
private SearchBuilder<StoragePoolJoinVO> spSearch;
private final SearchBuilder<StoragePoolJoinVO> spSearch;
private SearchBuilder<StoragePoolJoinVO> spIdSearch;
private final SearchBuilder<StoragePoolJoinVO> spIdSearch;
protected StoragePoolJoinDaoImpl() {

View File

@ -24,23 +24,21 @@ import java.util.List;
import java.util.Set;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.UserVmJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import javax.inject.Inject;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.response.NicResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.UserVmJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@ -55,7 +53,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
@Inject
private ConfigurationDao _configDao;
private SearchBuilder<UserVmJoinVO> VmDetailSearch;
private final SearchBuilder<UserVmJoinVO> VmDetailSearch;
protected UserVmJoinDaoImpl() {
@ -68,6 +66,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
}
@Override
public UserVmResponse newUserVmResponse(String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller) {
UserVmResponse userVmResponse = new UserVmResponse();
@ -216,8 +215,9 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
userVmResponse.setObjectName(objectName);
return userVmResponse;
}
}
@Override
public UserVmResponse setUserVmResponse(UserVmResponse userVmData, UserVmJoinVO uvo) {
Long securityGroupId = uvo.getSecurityGroupId();
if (securityGroupId != null && securityGroupId.longValue() != 0) {

View File

@ -20,26 +20,24 @@ import java.util.ArrayList;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.VolumeJoinVO;
import com.cloud.configuration.dao.ConfigurationDao;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.springframework.stereotype.Component;
import com.cloud.offering.ServiceOffering;
import com.cloud.storage.Storage;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.Volume;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.Volume;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
@ -53,9 +51,9 @@ public class VolumeJoinDaoImpl extends GenericDaoBase<VolumeJoinVO, Long> implem
@Inject
private ConfigurationDao _configDao;
private SearchBuilder<VolumeJoinVO> volSearch;
private final SearchBuilder<VolumeJoinVO> volSearch;
private SearchBuilder<VolumeJoinVO> volIdSearch;
private final SearchBuilder<VolumeJoinVO> volIdSearch;
protected VolumeJoinDaoImpl() {
@ -176,12 +174,12 @@ public class VolumeJoinDaoImpl extends GenericDaoBase<VolumeJoinVO, Long> implem
volResponse.setDestroyed(volume.getState() == Volume.State.Destroy);
boolean isExtractable = true;
if (volume.getVolumeType() != Volume.Type.DATADISK) { // Datadisk dont
// have any
// template
// dependence.
// have any
// template
// dependence.
if (volume.getTemplateId() > 0) { // For ISO based volumes template
// = null and we allow extraction
// of all ISO based volumes
// = null and we allow extraction
// of all ISO based volumes
isExtractable = volume.isExtractable() && volume.getTemplateType() != Storage.TemplateType.SYSTEM;
}
}

View File

@ -36,7 +36,6 @@ import com.cloud.storage.snapshot.SnapshotManager;
import com.cloud.user.AccountManager;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.DomainRouterDao;
@ -45,7 +44,7 @@ import com.cloud.vm.dao.UserVmDao;
@Component
@Local(value={AsyncJobExecutorContext.class})
public class AsyncJobExecutorContextImpl implements AsyncJobExecutorContext {
private String _name;
private String _name;
@Inject private AgentManager _agentMgr;
@Inject private NetworkManager _networkMgr;
@ -65,93 +64,93 @@ public class AsyncJobExecutorContextImpl implements AsyncJobExecutorContext {
@Inject private ManagementServer _managementServer;
@Override
public ManagementServer getManagementServer() {
return _managementServer;
}
@Override
public ManagementServer getManagementServer() {
return _managementServer;
}
@Override
public AgentManager getAgentMgr() {
return _agentMgr;
}
@Override
public AgentManager getAgentMgr() {
return _agentMgr;
}
@Override
public NetworkManager getNetworkMgr() {
return _networkMgr;
}
@Override
public NetworkManager getNetworkMgr() {
return _networkMgr;
}
@Override
public UserVmManager getVmMgr() {
return _vmMgr;
}
@Override
public UserVmManager getVmMgr() {
return _vmMgr;
}
@Override
public StorageManager getStorageMgr() {
return _storageMgr;
}
@Override
public StorageManager getStorageMgr() {
return _storageMgr;
}
/**server/src/com/cloud/async/AsyncJobExecutorContext.java
/**server/src/com/cloud/async/AsyncJobExecutorContext.java
* @return the _snapMgr
*/
@Override
@Override
public SnapshotManager getSnapshotMgr() {
return _snapMgr;
}
@Override
public AccountManager getAccountMgr() {
return _accountMgr;
}
public AccountManager getAccountMgr() {
return _accountMgr;
}
@Override
public EventDao getEventDao() {
return _eventDao;
}
@Override
public EventDao getEventDao() {
return _eventDao;
}
@Override
public UserVmDao getVmDao() {
return _vmDao;
}
@Override
public UserVmDao getVmDao() {
return _vmDao;
}
@Override
public AccountDao getAccountDao() {
return _accountDao;
}
@Override
public AccountDao getAccountDao() {
return _accountDao;
}
@Override
public VolumeDao getVolumeDao() {
return _volumeDao;
}
@Override
public VolumeDao getVolumeDao() {
return _volumeDao;
}
@Override
@Override
public DomainRouterDao getRouterDao() {
return _routerDao;
}
return _routerDao;
}
@Override
@Override
public IPAddressDao getIpAddressDao() {
return _ipAddressDao;
return _ipAddressDao;
}
@Override
@Override
public AsyncJobDao getJobDao() {
return _jobDao;
return _jobDao;
}
@Override
@Override
public UserDao getUserDao() {
return _userDao;
return _userDao;
}
@Override
public VirtualMachineManager getItMgr() {
return _itMgr;
}
@Override
public VirtualMachineManager getItMgr() {
return _itMgr;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
return true;
_name = name;
return true;
}
@Override
@ -166,6 +165,6 @@ public class AsyncJobExecutorContextImpl implements AsyncJobExecutorContext {
@Override
public String getName() {
return _name;
return _name;
}
}

View File

@ -35,7 +35,11 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
import org.apache.cloudstack.api.response.ExceptionResponse;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import org.springframework.stereotype.Component;
@ -43,15 +47,10 @@ import org.springframework.stereotype.Component;
import com.cloud.api.ApiDispatcher;
import com.cloud.api.ApiGsonHelper;
import com.cloud.api.ApiSerializerHelper;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ExceptionResponse;
import com.cloud.async.dao.AsyncJobDao;
import com.cloud.cluster.ClusterManager;
import com.cloud.cluster.ClusterManagerListener;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.StackMaid;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.exception.InvalidParameterValueException;
@ -64,7 +63,6 @@ import com.cloud.user.dao.AccountDao;
import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GlobalLock;
@ -80,7 +78,7 @@ import com.google.gson.reflect.TypeToken;
@Local(value={AsyncJobManager.class})
public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListener {
public static final Logger s_logger = Logger.getLogger(AsyncJobManagerImpl.class.getName());
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds
private static final int MAX_ONETIME_SCHEDULE_SIZE = 50;
private static final int HEARTBEAT_INTERVAL = 2000;
@ -98,167 +96,167 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
private long _jobExpireSeconds = 86400; // 1 day
private long _jobCancelThresholdSeconds = 3600; // 1 hour (for cancelling the jobs blocking other jobs)
private ApiDispatcher _dispatcher;
@Inject private ApiDispatcher _dispatcher;
private final ScheduledExecutorService _heartbeatScheduler =
Executors.newScheduledThreadPool(1, new NamedThreadFactory("AsyncJobMgr-Heartbeat"));
Executors.newScheduledThreadPool(1, new NamedThreadFactory("AsyncJobMgr-Heartbeat"));
private ExecutorService _executor;
@Override
public AsyncJobExecutorContext getExecutorContext() {
return _context;
}
@Override
public AsyncJobVO getAsyncJob(long jobId) {
return _jobDao.findById(jobId);
public AsyncJobExecutorContext getExecutorContext() {
return _context;
}
@Override
public AsyncJobVO findInstancePendingAsyncJob(String instanceType, long instanceId) {
return _jobDao.findInstancePendingAsyncJob(instanceType, instanceId);
public AsyncJobVO getAsyncJob(long jobId) {
return _jobDao.findById(jobId);
}
@Override
public AsyncJobVO findInstancePendingAsyncJob(String instanceType, long instanceId) {
return _jobDao.findInstancePendingAsyncJob(instanceType, instanceId);
}
@Override
public List<AsyncJobVO> findInstancePendingAsyncJobs(AsyncJob.Type instanceType, Long accountId) {
return _jobDao.findInstancePendingAsyncJobs(instanceType, accountId);
return _jobDao.findInstancePendingAsyncJobs(instanceType, accountId);
}
@Override
public long submitAsyncJob(AsyncJobVO job) {
return submitAsyncJob(job, false);
public long submitAsyncJob(AsyncJobVO job) {
return submitAsyncJob(job, false);
}
@Override @DB
public long submitAsyncJob(AsyncJobVO job, boolean scheduleJobExecutionInContext) {
Transaction txt = Transaction.currentTxn();
try {
txt.start();
job.setInitMsid(getMsid());
_jobDao.persist(job);
txt.commit();
Transaction txt = Transaction.currentTxn();
try {
txt.start();
job.setInitMsid(getMsid());
_jobDao.persist(job);
txt.commit();
// no sync source originally
job.setSyncSource(null);
scheduleExecution(job, scheduleJobExecutionInContext);
if(s_logger.isDebugEnabled()) {
// no sync source originally
job.setSyncSource(null);
scheduleExecution(job, scheduleJobExecutionInContext);
if(s_logger.isDebugEnabled()) {
s_logger.debug("submit async job-" + job.getId() + ", details: " + job.toString());
}
return job.getId();
} catch(Exception e) {
txt.rollback();
String errMsg = "Unable to schedule async job for command " + job.getCmd() + ", unexpected exception.";
return job.getId();
} catch(Exception e) {
txt.rollback();
String errMsg = "Unable to schedule async job for command " + job.getCmd() + ", unexpected exception.";
s_logger.warn(errMsg, e);
throw new CloudRuntimeException(errMsg);
}
}
}
@Override @DB
public void completeAsyncJob(long jobId, int jobStatus, int resultCode, Object resultObject) {
if(s_logger.isDebugEnabled()) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Complete async job-" + jobId + ", jobStatus: " + jobStatus +
", resultCode: " + resultCode + ", result: " + resultObject);
", resultCode: " + resultCode + ", result: " + resultObject);
}
Transaction txt = Transaction.currentTxn();
try {
txt.start();
AsyncJobVO job = _jobDao.findById(jobId);
if(job == null) {
if(s_logger.isDebugEnabled()) {
Transaction txt = Transaction.currentTxn();
try {
txt.start();
AsyncJobVO job = _jobDao.findById(jobId);
if(job == null) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus +
", resultCode: " + resultCode + ", result: " + resultObject);
", resultCode: " + resultCode + ", result: " + resultObject);
}
txt.rollback();
return;
}
txt.rollback();
return;
}
job.setCompleteMsid(getMsid());
job.setStatus(jobStatus);
job.setResultCode(resultCode);
job.setCompleteMsid(getMsid());
job.setStatus(jobStatus);
job.setResultCode(resultCode);
// reset attached object
job.setInstanceType(null);
job.setInstanceId(null);
// reset attached object
job.setInstanceType(null);
job.setInstanceId(null);
if (resultObject != null) {
if (resultObject != null) {
job.setResult(ApiSerializerHelper.toSerializedStringOld(resultObject));
}
}
job.setLastUpdated(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception while completing async job-" + jobId, e);
txt.rollback();
}
job.setLastUpdated(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception while completing async job-" + jobId, e);
txt.rollback();
}
}
@Override @DB
public void updateAsyncJobStatus(long jobId, int processStatus, Object resultObject) {
if(s_logger.isDebugEnabled()) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Update async-job progress, job-" + jobId + ", processStatus: " + processStatus +
", result: " + resultObject);
", result: " + resultObject);
}
Transaction txt = Transaction.currentTxn();
try {
txt.start();
AsyncJobVO job = _jobDao.findById(jobId);
if(job == null) {
if(s_logger.isDebugEnabled()) {
Transaction txt = Transaction.currentTxn();
try {
txt.start();
AsyncJobVO job = _jobDao.findById(jobId);
if(job == null) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus);
}
txt.rollback();
return;
}
txt.rollback();
return;
}
job.setProcessStatus(processStatus);
if(resultObject != null) {
job.setProcessStatus(processStatus);
if(resultObject != null) {
job.setResult(ApiSerializerHelper.toSerializedStringOld(resultObject));
}
job.setLastUpdated(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception while updating async job-" + jobId + " status: ", e);
txt.rollback();
}
job.setLastUpdated(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception while updating async job-" + jobId + " status: ", e);
txt.rollback();
}
}
@Override @DB
public void updateAsyncJobAttachment(long jobId, String instanceType, Long instanceId) {
if(s_logger.isDebugEnabled()) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Update async-job attachment, job-" + jobId + ", instanceType: " + instanceType +
", instanceId: " + instanceId);
", instanceId: " + instanceId);
}
Transaction txt = Transaction.currentTxn();
try {
txt.start();
Transaction txt = Transaction.currentTxn();
try {
txt.start();
AsyncJobVO job = _jobDao.createForUpdate();
//job.setInstanceType(instanceType);
job.setInstanceId(instanceId);
job.setLastUpdated(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
AsyncJobVO job = _jobDao.createForUpdate();
//job.setInstanceType(instanceType);
job.setInstanceId(instanceId);
job.setLastUpdated(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception while updating async job-" + jobId + " attachment: ", e);
txt.rollback();
}
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception while updating async job-" + jobId + " attachment: ", e);
txt.rollback();
}
}
@Override
public void syncAsyncJobExecution(AsyncJob job, String syncObjType, long syncObjId, long queueSizeLimit) {
// This method is re-entrant. If an API developer wants to synchronized on an object, e.g. the router,
// when executing business logic, they will call this method (actually a method in BaseAsyncCmd that calls this).
// This method will get called every time their business logic executes. The first time it exectues for a job
// there will be no sync source, but on subsequent execution there will be a sync souce. If this is the first
// time the job executes we queue the job, otherwise we just return so that the business logic can execute.
// This method is re-entrant. If an API developer wants to synchronized on an object, e.g. the router,
// when executing business logic, they will call this method (actually a method in BaseAsyncCmd that calls this).
// This method will get called every time their business logic executes. The first time it exectues for a job
// there will be no sync source, but on subsequent execution there will be a sync souce. If this is the first
// time the job executes we queue the job, otherwise we just return so that the business logic can execute.
if (job.getSyncSource() != null) {
return;
}
@ -267,29 +265,29 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
s_logger.debug("Sync job-" + job.getId() + " execution on object " + syncObjType + "." + syncObjId);
}
SyncQueueVO queue = null;
SyncQueueVO queue = null;
// to deal with temporary DB exceptions like DB deadlock/Lock-wait time out cased rollbacks
// we retry five times until we throw an exception
Random random = new Random();
// to deal with temporary DB exceptions like DB deadlock/Lock-wait time out cased rollbacks
// we retry five times until we throw an exception
Random random = new Random();
for(int i = 0; i < 5; i++) {
for(int i = 0; i < 5; i++) {
queue = _queueMgr.queue(syncObjType, syncObjId, SyncQueueItem.AsyncJobContentType, job.getId(), queueSizeLimit);
if(queue != null) {
if(queue != null) {
break;
}
try {
Thread.sleep(1000 + random.nextInt(5000));
} catch (InterruptedException e) {
}
}
try {
Thread.sleep(1000 + random.nextInt(5000));
} catch (InterruptedException e) {
}
}
if (queue == null) {
if (queue == null) {
throw new CloudRuntimeException("Unable to insert queue item into database, DB is full?");
} else {
throw new AsyncCommandQueued(queue, "job-" + job.getId() + " queued");
}
} else {
throw new AsyncCommandQueued(queue, "job-" + job.getId() + " queued");
}
}
@Override
@ -321,56 +319,56 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
@Override @DB
public AsyncJobResult queryAsyncJobResult(long jobId) {
if(s_logger.isTraceEnabled()) {
if(s_logger.isTraceEnabled()) {
s_logger.trace("Query async-job status, job-" + jobId);
}
Transaction txt = Transaction.currentTxn();
AsyncJobResult jobResult = new AsyncJobResult(jobId);
Transaction txt = Transaction.currentTxn();
AsyncJobResult jobResult = new AsyncJobResult(jobId);
try {
txt.start();
AsyncJobVO job = _jobDao.findById(jobId);
if(job != null) {
jobResult.setCmdOriginator(job.getCmdOriginator());
jobResult.setJobStatus(job.getStatus());
jobResult.setProcessStatus(job.getProcessStatus());
jobResult.setResult(job.getResult());
jobResult.setResultCode(job.getResultCode());
jobResult.setUuid(job.getUuid());
try {
txt.start();
AsyncJobVO job = _jobDao.findById(jobId);
if(job != null) {
jobResult.setCmdOriginator(job.getCmdOriginator());
jobResult.setJobStatus(job.getStatus());
jobResult.setProcessStatus(job.getProcessStatus());
jobResult.setResult(job.getResult());
jobResult.setResultCode(job.getResultCode());
jobResult.setUuid(job.getUuid());
if(job.getStatus() == AsyncJobResult.STATUS_SUCCEEDED ||
job.getStatus() == AsyncJobResult.STATUS_FAILED) {
if(job.getStatus() == AsyncJobResult.STATUS_SUCCEEDED ||
job.getStatus() == AsyncJobResult.STATUS_FAILED) {
if(s_logger.isDebugEnabled()) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Async job-" + jobId + " completed");
}
} else {
job.setLastPolled(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
}
} else {
if(s_logger.isDebugEnabled()) {
} else {
job.setLastPolled(DateUtil.currentGMTTime());
_jobDao.update(jobId, job);
}
} else {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Async job-" + jobId + " does not exist, invalid job id?");
}
jobResult.setJobStatus(AsyncJobResult.STATUS_FAILED);
jobResult.setResult("job-" + jobId + " does not exist");
}
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception while querying async job-" + jobId + " status: ", e);
jobResult.setJobStatus(AsyncJobResult.STATUS_FAILED);
jobResult.setResult("job-" + jobId + " does not exist");
}
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception while querying async job-" + jobId + " status: ", e);
jobResult.setJobStatus(AsyncJobResult.STATUS_FAILED);
jobResult.setResult("Exception: " + e.toString());
txt.rollback();
}
jobResult.setJobStatus(AsyncJobResult.STATUS_FAILED);
jobResult.setResult("Exception: " + e.toString());
txt.rollback();
}
if(s_logger.isTraceEnabled()) {
if(s_logger.isTraceEnabled()) {
s_logger.trace("Job status: " + jobResult.toString());
}
return jobResult;
return jobResult;
}
private void scheduleExecution(final AsyncJobVO job) {
@ -382,7 +380,7 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
if (executeInContext) {
runnable.run();
} else {
_executor.submit(runnable);
_executor.submit(runnable);
}
}
@ -394,9 +392,9 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
long jobId = 0;
try {
JmxUtil.registerMBean("AsyncJobManager", "Active Job " + job.getId(), new AsyncJobMBeanImpl(job));
JmxUtil.registerMBean("AsyncJobManager", "Active Job " + job.getId(), new AsyncJobMBeanImpl(job));
} catch(Exception e) {
s_logger.warn("Unable to register active job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e));
s_logger.warn("Unable to register active job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e));
}
BaseAsyncCmd cmdObj = null;
@ -492,12 +490,11 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
} finally {
try {
JmxUtil.unregisterMBean("AsyncJobManager", "Active Job " + job.getId());
JmxUtil.unregisterMBean("AsyncJobManager", "Active Job " + job.getId());
} catch(Exception e) {
s_logger.warn("Unable to unregister active job " + job.getId() + " from JMX monitoring");
s_logger.warn("Unable to unregister active job " + job.getId() + " from JMX monitoring");
}
StackMaid.current().exitCleanup();
txn.close();
NDC.pop();
}
@ -525,11 +522,11 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
_jobDao.update(job.getId(), job);
try {
scheduleExecution(job);
} catch(RejectedExecutionException e) {
s_logger.warn("Execution for job-" + job.getId() + " is rejected, return it to the queue for next turn");
_queueMgr.returnItem(item.getId());
}
scheduleExecution(job);
} catch(RejectedExecutionException e) {
s_logger.warn("Execution for job-" + job.getId() + " is rejected, return it to the queue for next turn");
_queueMgr.returnItem(item.getId());
}
} else {
if(s_logger.isDebugEnabled()) {
@ -542,120 +539,116 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
@Override
public void releaseSyncSource(AsyncJobExecutor executor) {
if(executor.getSyncSource() != null) {
if(s_logger.isDebugEnabled()) {
if(executor.getSyncSource() != null) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Release sync source for job-" + executor.getJob().getId() + " sync source: "
+ executor.getSyncSource().getContentType() + "-"
+ executor.getSyncSource().getContentId());
+ executor.getSyncSource().getContentType() + "-"
+ executor.getSyncSource().getContentId());
}
_queueMgr.purgeItem(executor.getSyncSource().getId());
checkQueue(executor.getSyncSource().getQueueId());
}
_queueMgr.purgeItem(executor.getSyncSource().getId());
checkQueue(executor.getSyncSource().getQueueId());
}
}
private void checkQueue(long queueId) {
while(true) {
try {
SyncQueueItemVO item = _queueMgr.dequeueFromOne(queueId, getMsid());
if(item != null) {
if(s_logger.isDebugEnabled()) {
while(true) {
try {
SyncQueueItemVO item = _queueMgr.dequeueFromOne(queueId, getMsid());
if(item != null) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Executing sync queue item: " + item.toString());
}
executeQueueItem(item, false);
} else {
break;
}
} catch(Throwable e) {
s_logger.error("Unexpected exception when kicking sync queue-" + queueId, e);
break;
}
}
executeQueueItem(item, false);
} else {
break;
}
} catch(Throwable e) {
s_logger.error("Unexpected exception when kicking sync queue-" + queueId, e);
break;
}
}
}
private Runnable getHeartbeatTask() {
return new Runnable() {
@Override
private Runnable getHeartbeatTask() {
return new Runnable() {
@Override
public void run() {
try {
List<SyncQueueItemVO> l = _queueMgr.dequeueFromAny(getMsid(), MAX_ONETIME_SCHEDULE_SIZE);
if(l != null && l.size() > 0) {
for(SyncQueueItemVO item: l) {
if(s_logger.isDebugEnabled()) {
try {
List<SyncQueueItemVO> l = _queueMgr.dequeueFromAny(getMsid(), MAX_ONETIME_SCHEDULE_SIZE);
if(l != null && l.size() > 0) {
for(SyncQueueItemVO item: l) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Execute sync-queue item: " + item.toString());
}
executeQueueItem(item, false);
}
}
} catch(Throwable e) {
s_logger.error("Unexpected exception when trying to execute queue item, ", e);
} finally {
StackMaid.current().exitCleanup();
}
}
};
}
executeQueueItem(item, false);
}
}
} catch(Throwable e) {
s_logger.error("Unexpected exception when trying to execute queue item, ", e);
}
}
};
}
@DB
private Runnable getGCTask() {
return new Runnable() {
@Override
@DB
private Runnable getGCTask() {
return new Runnable() {
@Override
public void run() {
GlobalLock scanLock = GlobalLock.getInternLock("AsyncJobManagerGC");
try {
if(scanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
try {
reallyRun();
} finally {
scanLock.unlock();
}
}
} finally {
scanLock.releaseRef();
}
}
GlobalLock scanLock = GlobalLock.getInternLock("AsyncJobManagerGC");
try {
if(scanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
try {
reallyRun();
} finally {
scanLock.unlock();
}
}
} finally {
scanLock.releaseRef();
}
}
public void reallyRun() {
try {
s_logger.trace("Begin cleanup expired async-jobs");
try {
s_logger.trace("Begin cleanup expired async-jobs");
Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - _jobExpireSeconds*1000);
Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - _jobExpireSeconds*1000);
// limit to 100 jobs per turn, this gives cleanup throughput as 600 jobs per minute
// hopefully this will be fast enough to balance potential growth of job table
List<AsyncJobVO> l = _jobDao.getExpiredJobs(cutTime, 100);
if(l != null && l.size() > 0) {
for(AsyncJobVO job : l) {
// limit to 100 jobs per turn, this gives cleanup throughput as 600 jobs per minute
// hopefully this will be fast enough to balance potential growth of job table
List<AsyncJobVO> l = _jobDao.getExpiredJobs(cutTime, 100);
if(l != null && l.size() > 0) {
for(AsyncJobVO job : l) {
expungeAsyncJob(job);
}
}
}
}
// forcefully cancel blocking queue items if they've been staying there for too long
List<SyncQueueItemVO> blockItems = _queueMgr.getBlockedQueueItems(_jobCancelThresholdSeconds*1000, false);
if(blockItems != null && blockItems.size() > 0) {
for(SyncQueueItemVO item : blockItems) {
List<SyncQueueItemVO> blockItems = _queueMgr.getBlockedQueueItems(_jobCancelThresholdSeconds*1000, false);
if(blockItems != null && blockItems.size() > 0) {
for(SyncQueueItemVO item : blockItems) {
if(item.getContentType().equalsIgnoreCase(SyncQueueItem.AsyncJobContentType)) {
completeAsyncJob(item.getContentId(), AsyncJobResult.STATUS_FAILED, 0,
getResetResultResponse("Job is cancelled as it has been blocking others for too long"));
}
// purge the item and resume queue processing
_queueMgr.purgeItem(item.getId());
}
}
// purge the item and resume queue processing
_queueMgr.purgeItem(item.getId());
}
}
s_logger.trace("End cleanup expired async-jobs");
} catch(Throwable e) {
s_logger.error("Unexpected exception when trying to execute queue item, ", e);
} finally {
StackMaid.current().exitCleanup();
}
}
s_logger.trace("End cleanup expired async-jobs");
} catch(Throwable e) {
s_logger.error("Unexpected exception when trying to execute queue item, ", e);
}
}
};
}
};
}
@DB
protected void expungeAsyncJob(AsyncJobVO job) {
@ -667,53 +660,50 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
txn.commit();
}
private long getMsid() {
if(_clusterMgr != null) {
private long getMsid() {
if(_clusterMgr != null) {
return _clusterMgr.getManagementNodeId();
}
return MacAddress.getMacAddress().toLong();
}
return MacAddress.getMacAddress().toLong();
}
private void cleanupPendingJobs(List<SyncQueueItemVO> l) {
if(l != null && l.size() > 0) {
for(SyncQueueItemVO item: l) {
if(s_logger.isInfoEnabled()) {
private void cleanupPendingJobs(List<SyncQueueItemVO> l) {
if(l != null && l.size() > 0) {
for(SyncQueueItemVO item: l) {
if(s_logger.isInfoEnabled()) {
s_logger.info("Discard left-over queue item: " + item.toString());
}
String contentType = item.getContentType();
String contentType = item.getContentType();
if(contentType != null && contentType.equalsIgnoreCase(SyncQueueItem.AsyncJobContentType)) {
Long jobId = item.getContentId();
if(jobId != null) {
s_logger.warn("Mark job as failed as its correspoding queue-item has been discarded. job id: " + jobId);
completeAsyncJob(jobId, AsyncJobResult.STATUS_FAILED, 0, getResetResultResponse("Execution was cancelled because of server shutdown"));
}
}
_queueMgr.purgeItem(item.getId());
}
}
}
Long jobId = item.getContentId();
if(jobId != null) {
s_logger.warn("Mark job as failed as its correspoding queue-item has been discarded. job id: " + jobId);
completeAsyncJob(jobId, AsyncJobResult.STATUS_FAILED, 0, getResetResultResponse("Execution was cancelled because of server shutdown"));
}
}
_queueMgr.purgeItem(item.getId());
}
}
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
_name = name;
int expireMinutes = NumbersUtil.parseInt(
_configDao.getValue(Config.JobExpireMinutes.key()), 24*60);
_jobExpireSeconds = (long)expireMinutes*60;
int expireMinutes = NumbersUtil.parseInt(
_configDao.getValue(Config.JobExpireMinutes.key()), 24*60);
_jobExpireSeconds = (long)expireMinutes*60;
_jobCancelThresholdSeconds = NumbersUtil.parseInt(
_configDao.getValue(Config.JobCancelThresholdMinutes.key()), 60);
_jobCancelThresholdSeconds *= 60;
_jobCancelThresholdSeconds = NumbersUtil.parseInt(
_configDao.getValue(Config.JobCancelThresholdMinutes.key()), 60);
_jobCancelThresholdSeconds *= 60;
_dispatcher = ApiDispatcher.getInstance();
try {
final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
final Properties dbProps = new Properties();
dbProps.load(new FileInputStream(dbPropsFile));
try {
final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
final Properties dbProps = new Properties();
dbProps.load(new FileInputStream(dbPropsFile));
final int cloudMaxActive = Integer.parseInt(dbProps.getProperty("db.cloud.maxActive"));
@ -721,63 +711,63 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
s_logger.info("Start AsyncJobManager thread pool in size " + poolSize);
_executor = Executors.newFixedThreadPool(poolSize, new NamedThreadFactory("Job-Executor"));
} catch (final Exception e) {
throw new ConfigurationException("Unable to load db.properties to configure AsyncJobManagerImpl");
}
} catch (final Exception e) {
throw new ConfigurationException("Unable to load db.properties to configure AsyncJobManagerImpl");
}
return true;
return true;
}
@Override
public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
}
@Override
public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long selfNodeId) {
for(ManagementServerHostVO msHost : nodeList) {
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
try {
txn.start();
List<SyncQueueItemVO> items = _queueMgr.getActiveQueueItems(msHost.getId(), true);
cleanupPendingJobs(items);
_jobDao.resetJobProcess(msHost.getId(), BaseCmd.INTERNAL_ERROR, getSerializedErrorMessage("job cancelled because of management server restart"));
txn.commit();
} catch(Throwable e) {
s_logger.warn("Unexpected exception ", e);
txn.rollback();
} finally {
txn.close();
}
}
public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long selfNodeId) {
for(ManagementServerHostVO msHost : nodeList) {
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
try {
txn.start();
List<SyncQueueItemVO> items = _queueMgr.getActiveQueueItems(msHost.getId(), true);
cleanupPendingJobs(items);
_jobDao.resetJobProcess(msHost.getId(), BaseCmd.INTERNAL_ERROR, getSerializedErrorMessage("job cancelled because of management server restart"));
txn.commit();
} catch(Throwable e) {
s_logger.warn("Unexpected exception ", e);
txn.rollback();
} finally {
txn.close();
}
}
}
@Override
public void onManagementNodeIsolated() {
}
public void onManagementNodeIsolated() {
}
@Override
public boolean start() {
try {
List<SyncQueueItemVO> l = _queueMgr.getActiveQueueItems(getMsid(), false);
cleanupPendingJobs(l);
_jobDao.resetJobProcess(getMsid(), BaseCmd.INTERNAL_ERROR, getSerializedErrorMessage("job cancelled because of management server restart"));
} catch(Throwable e) {
s_logger.error("Unexpected exception " + e.getMessage(), e);
}
try {
List<SyncQueueItemVO> l = _queueMgr.getActiveQueueItems(getMsid(), false);
cleanupPendingJobs(l);
_jobDao.resetJobProcess(getMsid(), BaseCmd.INTERNAL_ERROR, getSerializedErrorMessage("job cancelled because of management server restart"));
} catch(Throwable e) {
s_logger.error("Unexpected exception " + e.getMessage(), e);
}
_heartbeatScheduler.scheduleAtFixedRate(getHeartbeatTask(), HEARTBEAT_INTERVAL,
HEARTBEAT_INTERVAL, TimeUnit.MILLISECONDS);
_heartbeatScheduler.scheduleAtFixedRate(getGCTask(), GC_INTERVAL,
GC_INTERVAL, TimeUnit.MILLISECONDS);
_heartbeatScheduler.scheduleAtFixedRate(getHeartbeatTask(), HEARTBEAT_INTERVAL,
HEARTBEAT_INTERVAL, TimeUnit.MILLISECONDS);
_heartbeatScheduler.scheduleAtFixedRate(getGCTask(), GC_INTERVAL,
GC_INTERVAL, TimeUnit.MILLISECONDS);
return true;
}
private static ExceptionResponse getResetResultResponse(String errorMessage) {
ExceptionResponse resultObject = new ExceptionResponse();
resultObject.setErrorCode(BaseCmd.INTERNAL_ERROR);
resultObject.setErrorText(errorMessage);
return resultObject;
ExceptionResponse resultObject = new ExceptionResponse();
resultObject.setErrorCode(BaseCmd.INTERNAL_ERROR);
resultObject.setErrorText(errorMessage);
return resultObject;
}
private static String getSerializedErrorMessage(String errorMessage) {
@ -786,13 +776,13 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
@Override
public boolean stop() {
_heartbeatScheduler.shutdown();
_executor.shutdown();
_heartbeatScheduler.shutdown();
_executor.shutdown();
return true;
}
@Override
public String getName() {
return _name;
return _name;
}
}

View File

@ -31,7 +31,6 @@ import org.springframework.stereotype.Component;
import com.cloud.async.dao.SyncQueueDao;
import com.cloud.async.dao.SyncQueueItemDao;
import com.cloud.utils.DateUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
@ -50,190 +49,190 @@ public class SyncQueueManagerImpl implements SyncQueueManager {
@DB
public SyncQueueVO queue(String syncObjType, long syncObjId, String itemType, long itemId, long queueSizeLimit) {
Transaction txn = Transaction.currentTxn();
try {
txn.start();
try {
txn.start();
_syncQueueDao.ensureQueue(syncObjType, syncObjId);
SyncQueueVO queueVO = _syncQueueDao.find(syncObjType, syncObjId);
if(queueVO == null)
throw new CloudRuntimeException("Unable to queue item into DB, DB is full?");
_syncQueueDao.ensureQueue(syncObjType, syncObjId);
SyncQueueVO queueVO = _syncQueueDao.find(syncObjType, syncObjId);
if(queueVO == null)
throw new CloudRuntimeException("Unable to queue item into DB, DB is full?");
queueVO.setQueueSizeLimit(queueSizeLimit);
_syncQueueDao.update(queueVO.getId(), queueVO);
queueVO.setQueueSizeLimit(queueSizeLimit);
_syncQueueDao.update(queueVO.getId(), queueVO);
Date dt = DateUtil.currentGMTTime();
SyncQueueItemVO item = new SyncQueueItemVO();
item.setQueueId(queueVO.getId());
item.setContentType(itemType);
item.setContentId(itemId);
item.setCreated(dt);
Date dt = DateUtil.currentGMTTime();
SyncQueueItemVO item = new SyncQueueItemVO();
item.setQueueId(queueVO.getId());
item.setContentType(itemType);
item.setContentId(itemId);
item.setCreated(dt);
_syncQueueItemDao.persist(item);
txn.commit();
_syncQueueItemDao.persist(item);
txn.commit();
return queueVO;
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txn.rollback();
}
return null;
return queueVO;
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txn.rollback();
}
return null;
}
@Override
@DB
public SyncQueueItemVO dequeueFromOne(long queueId, Long msid) {
Transaction txt = Transaction.currentTxn();
try {
txt.start();
Transaction txt = Transaction.currentTxn();
try {
txt.start();
SyncQueueVO queueVO = _syncQueueDao.lockRow(queueId, true);
if(queueVO == null) {
s_logger.error("Sync queue(id: " + queueId + ") does not exist");
txt.commit();
return null;
}
SyncQueueVO queueVO = _syncQueueDao.lockRow(queueId, true);
if(queueVO == null) {
s_logger.error("Sync queue(id: " + queueId + ") does not exist");
txt.commit();
return null;
}
if(queueReadyToProcess(queueVO)) {
SyncQueueItemVO itemVO = _syncQueueItemDao.getNextQueueItem(queueVO.getId());
if(itemVO != null) {
Long processNumber = queueVO.getLastProcessNumber();
if(processNumber == null)
processNumber = new Long(1);
else
processNumber = processNumber + 1;
Date dt = DateUtil.currentGMTTime();
queueVO.setLastProcessNumber(processNumber);
queueVO.setLastUpdated(dt);
queueVO.setQueueSize(queueVO.getQueueSize() + 1);
_syncQueueDao.update(queueVO.getId(), queueVO);
if(queueReadyToProcess(queueVO)) {
SyncQueueItemVO itemVO = _syncQueueItemDao.getNextQueueItem(queueVO.getId());
if(itemVO != null) {
Long processNumber = queueVO.getLastProcessNumber();
if(processNumber == null)
processNumber = new Long(1);
else
processNumber = processNumber + 1;
Date dt = DateUtil.currentGMTTime();
queueVO.setLastProcessNumber(processNumber);
queueVO.setLastUpdated(dt);
queueVO.setQueueSize(queueVO.getQueueSize() + 1);
_syncQueueDao.update(queueVO.getId(), queueVO);
itemVO.setLastProcessMsid(msid);
itemVO.setLastProcessNumber(processNumber);
itemVO.setLastProcessTime(dt);
_syncQueueItemDao.update(itemVO.getId(), itemVO);
itemVO.setLastProcessMsid(msid);
itemVO.setLastProcessNumber(processNumber);
itemVO.setLastProcessTime(dt);
_syncQueueItemDao.update(itemVO.getId(), itemVO);
txt.commit();
return itemVO;
} else {
if(s_logger.isDebugEnabled())
s_logger.debug("Sync queue (" + queueId + ") is currently empty");
}
} else {
if(s_logger.isDebugEnabled())
s_logger.debug("There is a pending process in sync queue(id: " + queueId + ")");
}
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txt.rollback();
}
txt.commit();
return itemVO;
} else {
if(s_logger.isDebugEnabled())
s_logger.debug("Sync queue (" + queueId + ") is currently empty");
}
} else {
if(s_logger.isDebugEnabled())
s_logger.debug("There is a pending process in sync queue(id: " + queueId + ")");
}
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txt.rollback();
}
return null;
return null;
}
@Override
@DB
public List<SyncQueueItemVO> dequeueFromAny(Long msid, int maxItems) {
List<SyncQueueItemVO> resultList = new ArrayList<SyncQueueItemVO>();
Transaction txt = Transaction.currentTxn();
try {
txt.start();
List<SyncQueueItemVO> resultList = new ArrayList<SyncQueueItemVO>();
Transaction txt = Transaction.currentTxn();
try {
txt.start();
List<SyncQueueItemVO> l = _syncQueueItemDao.getNextQueueItems(maxItems);
if(l != null && l.size() > 0) {
for(SyncQueueItemVO item : l) {
SyncQueueVO queueVO = _syncQueueDao.lockRow(item.getQueueId(), true);
SyncQueueItemVO itemVO = _syncQueueItemDao.lockRow(item.getId(), true);
if(queueReadyToProcess(queueVO) && itemVO.getLastProcessNumber() == null) {
Long processNumber = queueVO.getLastProcessNumber();
if(processNumber == null)
processNumber = new Long(1);
else
processNumber = processNumber + 1;
List<SyncQueueItemVO> l = _syncQueueItemDao.getNextQueueItems(maxItems);
if(l != null && l.size() > 0) {
for(SyncQueueItemVO item : l) {
SyncQueueVO queueVO = _syncQueueDao.lockRow(item.getQueueId(), true);
SyncQueueItemVO itemVO = _syncQueueItemDao.lockRow(item.getId(), true);
if(queueReadyToProcess(queueVO) && itemVO.getLastProcessNumber() == null) {
Long processNumber = queueVO.getLastProcessNumber();
if(processNumber == null)
processNumber = new Long(1);
else
processNumber = processNumber + 1;
Date dt = DateUtil.currentGMTTime();
queueVO.setLastProcessNumber(processNumber);
queueVO.setLastUpdated(dt);
queueVO.setQueueSize(queueVO.getQueueSize() + 1);
_syncQueueDao.update(queueVO.getId(), queueVO);
Date dt = DateUtil.currentGMTTime();
queueVO.setLastProcessNumber(processNumber);
queueVO.setLastUpdated(dt);
queueVO.setQueueSize(queueVO.getQueueSize() + 1);
_syncQueueDao.update(queueVO.getId(), queueVO);
itemVO.setLastProcessMsid(msid);
itemVO.setLastProcessNumber(processNumber);
itemVO.setLastProcessTime(dt);
_syncQueueItemDao.update(item.getId(), itemVO);
itemVO.setLastProcessMsid(msid);
itemVO.setLastProcessNumber(processNumber);
itemVO.setLastProcessTime(dt);
_syncQueueItemDao.update(item.getId(), itemVO);
resultList.add(item);
}
}
}
txt.commit();
return resultList;
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txt.rollback();
}
return null;
resultList.add(item);
}
}
}
txt.commit();
return resultList;
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txt.rollback();
}
return null;
}
@Override
@DB
public void purgeItem(long queueItemId) {
Transaction txt = Transaction.currentTxn();
try {
txt.start();
Transaction txt = Transaction.currentTxn();
try {
txt.start();
SyncQueueItemVO itemVO = _syncQueueItemDao.findById(queueItemId);
if(itemVO != null) {
SyncQueueVO queueVO = _syncQueueDao.lockRow(itemVO.getQueueId(), true);
SyncQueueItemVO itemVO = _syncQueueItemDao.findById(queueItemId);
if(itemVO != null) {
SyncQueueVO queueVO = _syncQueueDao.lockRow(itemVO.getQueueId(), true);
_syncQueueItemDao.expunge(itemVO.getId());
_syncQueueItemDao.expunge(itemVO.getId());
//if item is active, reset queue information
if (itemVO.getLastProcessMsid() != null) {
queueVO.setLastUpdated(DateUtil.currentGMTTime());
//decrement the count
assert (queueVO.getQueueSize() > 0) : "Count reduce happens when it's already <= 0!";
queueVO.setQueueSize(queueVO.getQueueSize() - 1);
_syncQueueDao.update(queueVO.getId(), queueVO);
}
}
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txt.rollback();
}
//if item is active, reset queue information
if (itemVO.getLastProcessMsid() != null) {
queueVO.setLastUpdated(DateUtil.currentGMTTime());
//decrement the count
assert (queueVO.getQueueSize() > 0) : "Count reduce happens when it's already <= 0!";
queueVO.setQueueSize(queueVO.getQueueSize() - 1);
_syncQueueDao.update(queueVO.getId(), queueVO);
}
}
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txt.rollback();
}
}
@Override
@DB
public void returnItem(long queueItemId) {
Transaction txt = Transaction.currentTxn();
try {
txt.start();
Transaction txt = Transaction.currentTxn();
try {
txt.start();
SyncQueueItemVO itemVO = _syncQueueItemDao.findById(queueItemId);
if(itemVO != null) {
SyncQueueVO queueVO = _syncQueueDao.lockRow(itemVO.getQueueId(), true);
SyncQueueItemVO itemVO = _syncQueueItemDao.findById(queueItemId);
if(itemVO != null) {
SyncQueueVO queueVO = _syncQueueDao.lockRow(itemVO.getQueueId(), true);
itemVO.setLastProcessMsid(null);
itemVO.setLastProcessNumber(null);
itemVO.setLastProcessTime(null);
_syncQueueItemDao.update(queueItemId, itemVO);
itemVO.setLastProcessMsid(null);
itemVO.setLastProcessNumber(null);
itemVO.setLastProcessTime(null);
_syncQueueItemDao.update(queueItemId, itemVO);
queueVO.setLastUpdated(DateUtil.currentGMTTime());
_syncQueueDao.update(queueVO.getId(), queueVO);
}
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txt.rollback();
}
queueVO.setLastUpdated(DateUtil.currentGMTTime());
_syncQueueDao.update(queueVO.getId(), queueVO);
}
txt.commit();
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
txt.rollback();
}
}
@Override
public List<SyncQueueItemVO> getActiveQueueItems(Long msid, boolean exclusive) {
return _syncQueueItemDao.getActiveQueueItems(msid, exclusive);
public List<SyncQueueItemVO> getActiveQueueItems(Long msid, boolean exclusive) {
return _syncQueueItemDao.getActiveQueueItems(msid, exclusive);
}
@Override
@ -243,8 +242,8 @@ public class SyncQueueManagerImpl implements SyncQueueManager {
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
return true;
_name = name;
return true;
}
@Override
@ -259,7 +258,7 @@ public class SyncQueueManagerImpl implements SyncQueueManager {
@Override
public String getName() {
return _name;
return _name;
}
private boolean queueReadyToProcess(SyncQueueVO queueVO) {

View File

@ -35,10 +35,7 @@ import com.cloud.capacity.CapacityVO;
import com.cloud.storage.Storage;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.dao.StoragePoolDao;
import com.cloud.storage.dao.StoragePoolDaoImpl;
import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
@ -60,116 +57,116 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART1 = "SELECT DISTINCT capacity.cluster_id FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster on (cluster.id = capacity.cluster_id AND cluster.removed is NULL) WHERE ";
private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART2 = " AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ? " +
"AND cluster_id IN (SELECT distinct cluster_id FROM `cloud`.`op_host_capacity` WHERE ";
"AND cluster_id IN (SELECT distinct cluster_id FROM `cloud`.`op_host_capacity` WHERE ";
private static final String LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART3 = " AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ?) ";
private final SearchBuilder<CapacityVO> _hostIdTypeSearch;
private final SearchBuilder<CapacityVO> _hostOrPoolIdSearch;
private final SearchBuilder<CapacityVO> _hostOrPoolIdSearch;
protected GenericSearchBuilder<CapacityVO, SummedCapacity> SummedCapacitySearch;
private SearchBuilder<CapacityVO> _allFieldsSearch;
private final SearchBuilder<CapacityVO> _allFieldsSearch;
@Inject protected StoragePoolDao _storagePoolDao;
private static final String LIST_HOSTS_IN_CLUSTER_WITH_ENOUGH_CAPACITY = "SELECT a.host_id FROM (host JOIN op_host_capacity a ON host.id = a.host_id AND host.cluster_id = ? AND host.type = ? " +
"AND (a.total_capacity * ? - a.used_capacity) >= ? and a.capacity_type = 1) " +
"JOIN op_host_capacity b ON a.host_id = b.host_id AND b.total_capacity - b.used_capacity >= ? AND b.capacity_type = 0";
"AND (a.total_capacity * ? - a.used_capacity) >= ? and a.capacity_type = 1) " +
"JOIN op_host_capacity b ON a.host_id = b.host_id AND b.total_capacity - b.used_capacity >= ? AND b.capacity_type = 0";
private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART1 = "SELECT cluster_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) FROM `cloud`.`op_host_capacity` WHERE " ;
private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_PART2 = " AND capacity_type = ? GROUP BY cluster_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) ASC";
private static final String LIST_PODSINZONE_BY_HOST_CAPACITIES = "SELECT DISTINCT capacity.pod_id FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod " +
" ON (pod.id = capacity.pod_id AND pod.removed is NULL) WHERE " +
" capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ? " +
" AND pod_id IN (SELECT distinct pod_id FROM `cloud`.`op_host_capacity` WHERE " +
" capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ?) ";
" ON (pod.id = capacity.pod_id AND pod.removed is NULL) WHERE " +
" capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ? " +
" AND pod_id IN (SELECT distinct pod_id FROM `cloud`.`op_host_capacity` WHERE " +
" capacity.data_center_id = ? AND capacity_type = ? AND ((total_capacity * ?) - used_capacity + reserved_capacity) >= ?) ";
private static final String ORDER_PODS_BY_AGGREGATE_CAPACITY = "SELECT pod_id, SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) FROM `cloud`.`op_host_capacity` WHERE data_center_id = ? " +
" AND capacity_type = ? GROUP BY pod_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) ASC";
" AND capacity_type = ? GROUP BY pod_id ORDER BY SUM(used_capacity+reserved_capacity)/SUM(total_capacity * ?) ASC";
private static final String LIST_CAPACITY_BY_RESOURCE_STATE = "SELECT capacity.data_center_id, sum(capacity.used_capacity), sum(capacity.reserved_quantity), sum(capacity.total_capacity), capacity_capacity_type "+
"FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`data_center` dc ON (dc.id = capacity.data_center_id AND dc.removed is NULL)"+
"FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod ON (pod.id = capacity.pod_id AND pod.removed is NULL)"+
"FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster ON (cluster.id = capacity.cluster_id AND cluster.removed is NULL)"+
"FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host` host ON (host.id = capacity.host_id AND host.removed is NULL)"+
"WHERE dc.allocation_state = ? AND pod.allocation_state = ? AND cluster.allocation_state = ? AND host.resource_state = ? AND capacity_type not in (3,4) ";
"FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`data_center` dc ON (dc.id = capacity.data_center_id AND dc.removed is NULL)"+
"FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host_pod_ref` pod ON (pod.id = capacity.pod_id AND pod.removed is NULL)"+
"FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`cluster` cluster ON (cluster.id = capacity.cluster_id AND cluster.removed is NULL)"+
"FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host` host ON (host.id = capacity.host_id AND host.removed is NULL)"+
"WHERE dc.allocation_state = ? AND pod.allocation_state = ? AND cluster.allocation_state = ? AND host.resource_state = ? AND capacity_type not in (3,4) ";
private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
"((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
" capacity.capacity_type, capacity.data_center_id "+
"FROM `cloud`.`op_host_capacity` capacity "+
"WHERE total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled'";
"((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
" capacity.capacity_type, capacity.data_center_id "+
"FROM `cloud`.`op_host_capacity` capacity "+
"WHERE total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled'";
private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART2 = " GROUP BY data_center_id, capacity_type order by percent desc limit ";
private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
"((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
" capacity.capacity_type, capacity.data_center_id, pod_id "+
"FROM `cloud`.`op_host_capacity` capacity "+
"WHERE total_capacity > 0 AND pod_id is not null AND capacity_state='Enabled'";
"((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
" capacity.capacity_type, capacity.data_center_id, pod_id "+
"FROM `cloud`.`op_host_capacity` capacity "+
"WHERE total_capacity > 0 AND pod_id is not null AND capacity_state='Enabled'";
private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART2 = " GROUP BY pod_id, capacity_type order by percent desc limit ";
private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
"((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
"capacity.capacity_type, capacity.data_center_id, pod_id, cluster_id "+
"FROM `cloud`.`op_host_capacity` capacity "+
"WHERE total_capacity > 0 AND cluster_id is not null AND capacity_state='Enabled'";
"((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
"capacity.capacity_type, capacity.data_center_id, pod_id, cluster_id "+
"FROM `cloud`.`op_host_capacity` capacity "+
"WHERE total_capacity > 0 AND cluster_id is not null AND capacity_state='Enabled'";
private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2 = " GROUP BY cluster_id, capacity_type order by percent desc limit ";
private static final String UPDATE_CAPACITY_STATE = "UPDATE `cloud`.`op_host_capacity` SET capacity_state = ? WHERE ";
private static final String LIST_CLUSTERS_CROSSING_THRESHOLD = "SELECT cluster_id " +
"FROM (SELECT cluster_id, ( (sum(capacity.used_capacity) + sum(capacity.reserved_capacity) + ?)/sum(total_capacity) ) ratio "+
"FROM `cloud`.`op_host_capacity` capacity "+
"WHERE capacity.data_center_id = ? AND capacity.capacity_type = ? AND capacity.total_capacity > 0 "+
"GROUP BY cluster_id) tmp " +
"WHERE tmp.ratio > ? ";
"FROM (SELECT cluster_id, ( (sum(capacity.used_capacity) + sum(capacity.reserved_capacity) + ?)/sum(total_capacity) ) ratio "+
"FROM `cloud`.`op_host_capacity` capacity "+
"WHERE capacity.data_center_id = ? AND capacity.capacity_type = ? AND capacity.total_capacity > 0 "+
"GROUP BY cluster_id) tmp " +
"WHERE tmp.ratio > ? ";
public CapacityDaoImpl() {
_hostIdTypeSearch = createSearchBuilder();
_hostIdTypeSearch.and("hostId", _hostIdTypeSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
_hostIdTypeSearch.and("type", _hostIdTypeSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
_hostIdTypeSearch.done();
_hostIdTypeSearch = createSearchBuilder();
_hostIdTypeSearch.and("hostId", _hostIdTypeSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
_hostIdTypeSearch.and("type", _hostIdTypeSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
_hostIdTypeSearch.done();
_hostOrPoolIdSearch = createSearchBuilder();
_hostOrPoolIdSearch.and("hostId", _hostOrPoolIdSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
_hostOrPoolIdSearch.done();
_hostOrPoolIdSearch = createSearchBuilder();
_hostOrPoolIdSearch.and("hostId", _hostOrPoolIdSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
_hostOrPoolIdSearch.done();
_allFieldsSearch = createSearchBuilder();
_allFieldsSearch.and("id", _allFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("hostId", _allFieldsSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("zoneId", _allFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("podId", _allFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("clusterId", _allFieldsSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("capacityType", _allFieldsSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("capacityState", _allFieldsSearch.entity().getCapacityState(), SearchCriteria.Op.EQ);
_allFieldsSearch = createSearchBuilder();
_allFieldsSearch.and("id", _allFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("hostId", _allFieldsSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("zoneId", _allFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("podId", _allFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("clusterId", _allFieldsSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("capacityType", _allFieldsSearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
_allFieldsSearch.and("capacityState", _allFieldsSearch.entity().getCapacityState(), SearchCriteria.Op.EQ);
_allFieldsSearch.done();
_allFieldsSearch.done();
}
@Override
public List<Long> listClustersCrossingThreshold(short capacityType, Long zoneId, Float disableThreshold, long compute_requested, Float overProvFactor){
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
StringBuilder sql = new StringBuilder(LIST_CLUSTERS_CROSSING_THRESHOLD);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
StringBuilder sql = new StringBuilder(LIST_CLUSTERS_CROSSING_THRESHOLD);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, compute_requested);
pstmt.setLong(2, zoneId);
pstmt.setShort(3, capacityType);
pstmt.setFloat(4, disableThreshold*overProvFactor);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, compute_requested);
pstmt.setLong(2, zoneId);
pstmt.setShort(3, capacityType);
pstmt.setFloat(4, disableThreshold*overProvFactor);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(rs.getLong(1));
}
return result;
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + sql, e);
} catch (Throwable e) {
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(rs.getLong(1));
}
return result;
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + sql, e);
} catch (Throwable e) {
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
/*public static String preparePlaceHolders(int length) {
StringBuilder builder = new StringBuilder();
@ -247,17 +244,17 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
List<SummedCapacity> result = new ArrayList<SummedCapacity>();
switch(level){
case 1: // List all the capacities grouped by zone, capacity Type
finalQuery.append(LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1);
break;
case 1: // List all the capacities grouped by zone, capacity Type
finalQuery.append(LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1);
break;
case 2: // List all the capacities grouped by pod, capacity Type
finalQuery.append(LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1);
break;
case 2: // List all the capacities grouped by pod, capacity Type
finalQuery.append(LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1);
break;
case 3: // List all the capacities grouped by cluster, capacity Type
finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1);
break;
case 3: // List all the capacities grouped by cluster, capacity Type
finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1);
break;
}
if (zoneId != null){
@ -294,9 +291,9 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
SummedCapacity summedCapacity = new SummedCapacity( rs.getLong(1), rs.getLong(2), rs.getFloat(3),
(short)rs.getLong(4), rs.getLong(5),
level != 1 ? rs.getLong(6): null,
level == 3 ? rs.getLong(7): null);
(short)rs.getLong(4), rs.getLong(5),
level != 1 ? rs.getLong(6): null,
level == 3 ? rs.getLong(7): null);
result.add(summedCapacity);
}
@ -312,8 +309,8 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
@Override
public List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId){
SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
SummedCapacitySearch.select("dcId", Func.NATIVE, SummedCapacitySearch.entity().getDataCenterId());
SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
SummedCapacitySearch.select("dcId", Func.NATIVE, SummedCapacitySearch.entity().getDataCenterId());
SummedCapacitySearch.select("sumUsed", Func.SUM, SummedCapacitySearch.entity().getUsedCapacity());
SummedCapacitySearch.select("sumReserved", Func.SUM, SummedCapacitySearch.entity().getReservedCapacity());
SummedCapacitySearch.select("sumTotal", Func.SUM, SummedCapacitySearch.entity().getTotalCapacity());
@ -326,16 +323,16 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
}
if (zoneId != null){
SummedCapacitySearch.and("dcId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
SummedCapacitySearch.and("dcId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
}
if (podId != null){
SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
}
if (clusterId != null){
SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
}
if (capacityType != null){
SummedCapacitySearch.and("capacityType", SummedCapacitySearch.entity().getCapacityType(), Op.EQ);
SummedCapacitySearch.and("capacityType", SummedCapacitySearch.entity().getCapacityType(), Op.EQ);
}
SummedCapacitySearch.done();
@ -343,16 +340,16 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
SearchCriteria<SummedCapacity> sc = SummedCapacitySearch.create();
if (zoneId != null){
sc.setParameters("dcId", zoneId);
sc.setParameters("dcId", zoneId);
}
if (podId != null){
sc.setParameters("podId", podId);
sc.setParameters("podId", podId);
}
if (clusterId != null){
sc.setParameters("clusterId", clusterId);
sc.setParameters("clusterId", clusterId);
}
if (capacityType != null){
sc.setParameters("capacityType", capacityType);
sc.setParameters("capacityType", capacityType);
}
Filter filter = new Filter(CapacityVO.class, null, true, null, null);
@ -387,45 +384,45 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
@Override
public CapacityVO findByHostIdType(Long hostId, short capacityType) {
SearchCriteria<CapacityVO> sc = _hostIdTypeSearch.create();
sc.setParameters("hostId", hostId);
sc.setParameters("type", capacityType);
return findOneBy(sc);
SearchCriteria<CapacityVO> sc = _hostIdTypeSearch.create();
sc.setParameters("hostId", hostId);
sc.setParameters("type", capacityType);
return findOneBy(sc);
}
@Override
public List<Long> listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor){
Transaction txn = Transaction.currentTxn();
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
StringBuilder sql = new StringBuilder(LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART1);
if(isZone){
sql.append("capacity.data_center_id = ?");
sql.append("capacity.data_center_id = ?");
}else{
sql.append("capacity.pod_id = ?");
sql.append("capacity.pod_id = ?");
}
sql.append(LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART2);
if(isZone){
sql.append("capacity.data_center_id = ?");
sql.append("capacity.data_center_id = ?");
}else{
sql.append("capacity.pod_id = ?");
sql.append("capacity.pod_id = ?");
}
sql.append(LIST_CLUSTERSINZONE_BY_HOST_CAPACITIES_PART3);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, id);
pstmt.setShort(2, CapacityVO.CAPACITY_TYPE_CPU);
pstmt.setFloat(3, cpuOverprovisioningFactor);
pstmt.setLong(4, requiredCpu);
pstmt.setLong(5, id);
pstmt.setShort(6, CapacityVO.CAPACITY_TYPE_MEMORY);
pstmt.setFloat(7, 1);
pstmt.setLong(8, requiredRam);
pstmt.setShort(2, CapacityVO.CAPACITY_TYPE_CPU);
pstmt.setFloat(3, cpuOverprovisioningFactor);
pstmt.setLong(4, requiredCpu);
pstmt.setLong(5, id);
pstmt.setShort(6, CapacityVO.CAPACITY_TYPE_MEMORY);
pstmt.setFloat(7, 1);
pstmt.setLong(8, requiredRam);
ResultSet rs = pstmt.executeQuery();
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
result.add(rs.getLong(1));
}
@ -440,7 +437,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
@Override
public List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor){
Transaction txn = Transaction.currentTxn();
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
@ -448,10 +445,10 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, clusterId);
pstmt.setString(2, hostType);
pstmt.setFloat(3, cpuOverprovisioningFactor);
pstmt.setLong(4, requiredCpu);
pstmt.setLong(5, requiredRam);
pstmt.setString(2, hostType);
pstmt.setFloat(3, cpuOverprovisioningFactor);
pstmt.setLong(4, requiredCpu);
pstmt.setLong(5, requiredRam);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
@ -465,60 +462,60 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
}
}
public static class SummedCapacity {
public long sumUsed;
public long sumReserved;
public long sumTotal;
public Float percentUsed;
public short capacityType;
public Long clusterId;
public Long podId;
public Long dcId;
public SummedCapacity() {
}
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
short capacityType, Long clusterId, Long podId) {
super();
this.sumUsed = sumUsed;
this.sumReserved = sumReserved;
this.sumTotal = sumTotal;
this.capacityType = capacityType;
this.clusterId = clusterId;
this.podId = podId;
}
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
public static class SummedCapacity {
public long sumUsed;
public long sumReserved;
public long sumTotal;
public Float percentUsed;
public short capacityType;
public Long clusterId;
public Long podId;
public Long dcId;
public SummedCapacity() {
}
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
short capacityType, Long clusterId, Long podId) {
super();
this.sumUsed = sumUsed;
this.sumReserved = sumReserved;
this.sumTotal = sumTotal;
this.capacityType = capacityType;
this.clusterId = clusterId;
this.podId = podId;
}
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
short capacityType, Long clusterId, Long podId, Long zoneId) {
this(sumUsed, sumReserved, sumTotal, capacityType, clusterId, podId);
this.dcId = zoneId;
}
this(sumUsed, sumReserved, sumTotal, capacityType, clusterId, podId);
this.dcId = zoneId;
}
public SummedCapacity(long sumUsed, long sumTotal, float percentUsed, short capacityType, Long zoneId, Long podId, Long clusterId) {
super();
this.sumUsed = sumUsed;
this.sumTotal = sumTotal;
this.percentUsed = percentUsed;
this.capacityType = capacityType;
public SummedCapacity(long sumUsed, long sumTotal, float percentUsed, short capacityType, Long zoneId, Long podId, Long clusterId) {
super();
this.sumUsed = sumUsed;
this.sumTotal = sumTotal;
this.percentUsed = percentUsed;
this.capacityType = capacityType;
this.clusterId = clusterId;
this.podId = podId;
this.dcId = zoneId;
}
public Short getCapacityType() {
return capacityType;
}
public Long getUsedCapacity() {
return sumUsed;
}
public long getReservedCapacity() {
return sumReserved;
}
public Long getTotalCapacity() {
return sumTotal;
}
public Long getDataCenterId() {
public Short getCapacityType() {
return capacityType;
}
public Long getUsedCapacity() {
return sumUsed;
}
public long getReservedCapacity() {
return sumReserved;
}
public Long getTotalCapacity() {
return sumTotal;
}
public Long getDataCenterId() {
return dcId;
}
public Long getClusterId() {
public Long getClusterId() {
return clusterId;
}
public Long getPodId() {
@ -527,63 +524,64 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
public Float getPercentUsed() {
return percentUsed;
}
}
public List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId){
}
@Override
public List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId){
SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
SummedCapacitySearch.select("sumUsed", Func.SUM, SummedCapacitySearch.entity().getUsedCapacity());
SummedCapacitySearch.select("sumTotal", Func.SUM, SummedCapacitySearch.entity().getTotalCapacity());
SummedCapacitySearch.select("capacityType", Func.NATIVE, SummedCapacitySearch.entity().getCapacityType());
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getCapacityType());
if(zoneId != null){
SummedCapacitySearch.and("zoneId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
SummedCapacitySearch.and("zoneId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
}
if (podId != null){
SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
}
if (clusterId != null){
SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
}
SummedCapacitySearch.done();
SearchCriteria<SummedCapacity> sc = SummedCapacitySearch.create();
if (zoneId != null){
sc.setParameters("zoneId", zoneId);
sc.setParameters("zoneId", zoneId);
}
if (podId != null){
sc.setParameters("podId", podId);
sc.setParameters("podId", podId);
}
if (clusterId != null){
sc.setParameters("clusterId", clusterId);
sc.setParameters("clusterId", clusterId);
}
return customSearchIncludingRemoved(sc, null);
}
}
@Override
public List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId, Long podId, Long clusterId){
@Override
public List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId, Long podId, Long clusterId){
SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
SummedCapacitySearch.select("sumUsed", Func.SUM, SummedCapacitySearch.entity().getUsedCapacity());
SummedCapacitySearch.select("sumTotal", Func.SUM, SummedCapacitySearch.entity().getTotalCapacity());
SummedCapacitySearch.select("capacityType", Func.NATIVE, SummedCapacitySearch.entity().getCapacityType());
SummedCapacitySearch.and("capacityType", SummedCapacitySearch.entity().getCapacityType(), Op.EQ);
SearchBuilder<StoragePoolVO> nonSharedStorage = _storagePoolDao.createSearchBuilder();
nonSharedStorage.and("poolTypes", nonSharedStorage.entity().getPoolType(), SearchCriteria.Op.IN);
SummedCapacitySearch.join("nonSharedStorage", nonSharedStorage, nonSharedStorage.entity().getId(), SummedCapacitySearch.entity().getHostOrPoolId(), JoinType.INNER);
nonSharedStorage.done();
SearchBuilder<StoragePoolVO> nonSharedStorage = _storagePoolDao.createSearchBuilder();
nonSharedStorage.and("poolTypes", nonSharedStorage.entity().getPoolType(), SearchCriteria.Op.IN);
SummedCapacitySearch.join("nonSharedStorage", nonSharedStorage, nonSharedStorage.entity().getId(), SummedCapacitySearch.entity().getHostOrPoolId(), JoinType.INNER);
nonSharedStorage.done();
if(zoneId != null){
SummedCapacitySearch.and("zoneId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
SummedCapacitySearch.and("zoneId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
}
if (podId != null){
SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
}
if (clusterId != null){
SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
SummedCapacitySearch.and("clusterId", SummedCapacitySearch.entity().getClusterId(), Op.EQ);
}
SummedCapacitySearch.done();
@ -592,17 +590,17 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
sc.setJoinParameters("nonSharedStorage", "poolTypes", Storage.getNonSharedStoragePoolTypes().toArray());
sc.setParameters("capacityType", Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED);
if (zoneId != null){
sc.setParameters("zoneId", zoneId);
sc.setParameters("zoneId", zoneId);
}
if (podId != null){
sc.setParameters("podId", podId);
sc.setParameters("podId", podId);
}
if (clusterId != null){
sc.setParameters("clusterId", clusterId);
sc.setParameters("clusterId", clusterId);
}
return customSearchIncludingRemoved(sc, null);
}
}
@Override
public boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId, Long hostId) {

View File

@ -1,52 +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 com.cloud.cluster;
/**
* TaskManager helps business logic deal with clustering failover.
* Say you're writing code that introduces an inconsistent state over
* of your operation? Who will come back to cleanup this state? TaskManager
* with different content during your process. If the server dies, TaskManager
* running elsewhere. If there are no clustered servers, then TaskManager will
* cleanup when the dead server resumes.
*
*/
public interface CheckPointManager {
/**
* responsible for cleaning up.
*
* @param context context information to be stored.
* @return Check point id.
*/
long pushCheckPoint(CleanupMaid context);
/**
* update the task with new context
* @param taskId
* @param updatedContext new updated context.
*/
void updateCheckPointState(long taskId, CleanupMaid updatedContext);
/**
* removes the task as it is completed.
*
* @param taskId
*/
void popCheckPoint(long taskId);
}

View File

@ -1,247 +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 com.cloud.cluster;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.cluster.dao.StackMaidDao;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.serializer.SerializerHelper;
import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GlobalLock;
@Component
@Local(value=CheckPointManager.class)
public class CheckPointManagerImpl implements CheckPointManager, Manager, ClusterManagerListener {
private static final Logger s_logger = Logger.getLogger(CheckPointManagerImpl.class);
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds
private int _cleanupRetryInterval;
private String _name;
@Inject
private StackMaidDao _maidDao;
@Inject
private ClusterManager _clusterMgr;
@Inject ConfigurationDao _configDao;
long _msId;
private final ScheduledExecutorService _cleanupScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Task-Cleanup"));
protected CheckPointManagerImpl() {
}
@Override
public boolean configure(String name, Map<String, Object> xmlParams) throws ConfigurationException {
_name = name;
if (s_logger.isInfoEnabled()) {
s_logger.info("Start configuring StackMaidManager : " + name);
}
StackMaid.init(ManagementServerNode.getManagementServerId());
_msId = ManagementServerNode.getManagementServerId();
_clusterMgr.registerListener(this);
Map<String, String> params = _configDao.getConfiguration(xmlParams);
_cleanupRetryInterval = NumbersUtil.parseInt(params.get(Config.TaskCleanupRetryInterval.key()), 600);
_maidDao.takeover(_msId, _msId);
return true;
}
private void cleanupLeftovers(List<CheckPointVO> l) {
for (CheckPointVO maid : l) {
if (StackMaid.doCleanup(maid)) {
_maidDao.expunge(maid.getId());
}
}
}
@Override
public void onManagementNodeIsolated() {
}
@DB
private Runnable getGCTask() {
return new Runnable() {
@Override
public void run() {
GlobalLock scanLock = GlobalLock.getInternLock("StackMaidManagerGC");
try {
if (scanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
try {
reallyRun();
} finally {
scanLock.unlock();
}
}
} finally {
scanLock.releaseRef();
}
}
public void reallyRun() {
try {
Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - 7200000);
List<CheckPointVO> l = _maidDao.listLeftoversByCutTime(cutTime);
cleanupLeftovers(l);
} catch (Throwable e) {
s_logger.error("Unexpected exception when trying to execute queue item, ", e);
}
}
};
}
@Override
public boolean start() {
_cleanupScheduler.schedule(new CleanupTask(), _cleanupRetryInterval > 0 ? _cleanupRetryInterval : 600, TimeUnit.SECONDS);
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public String getName() {
return _name;
}
@Override
public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) {
// Nothing to do
}
@Override
public void onManagementNodeLeft(List<ManagementServerHostVO> nodeList, long selfNodeId) {
for (ManagementServerHostVO node : nodeList) {
if (_maidDao.takeover(node.getMsid(), selfNodeId)) {
s_logger.info("Taking over from " + node.getMsid());
_cleanupScheduler.execute(new CleanupTask());
}
}
}
@Override
@DB
public long pushCheckPoint(CleanupMaid context) {
long seq = _maidDao.pushCleanupDelegate(_msId, 0, context.getClass().getName(), context);
return seq;
}
@Override
@DB
public void updateCheckPointState(long taskId, CleanupMaid updatedContext) {
CheckPointVO task = _maidDao.createForUpdate();
task.setDelegate(updatedContext.getClass().getName());
task.setContext(SerializerHelper.toSerializedStringOld(updatedContext));
_maidDao.update(taskId, task);
}
@Override
@DB
public void popCheckPoint(long taskId) {
_maidDao.remove(taskId);
}
protected boolean cleanup(CheckPointVO task) {
s_logger.info("Cleaning up " + task);
CleanupMaid delegate = (CleanupMaid)SerializerHelper.fromSerializedString(task.getContext());
assert delegate.getClass().getName().equals(task.getDelegate()) : "Deserializer says " + delegate.getClass().getName() + " but it's suppose to be " + task.getDelegate();
int result = delegate.cleanup(this);
if (result <= 0) {
if (result == 0) {
s_logger.info("Successfully cleaned up " + task.getId());
} else {
s_logger.warn("Unsuccessful in cleaning up " + task + ". Procedure to cleanup manaully: " + delegate.getCleanupProcedure());
}
popCheckPoint(task.getId());
return true;
} else {
s_logger.error("Unable to cleanup " + task.getId());
return false;
}
}
class CleanupTask implements Runnable {
private Date _curDate;
public CleanupTask() {
_curDate = new Date();
}
@Override
public void run() {
try {
List<CheckPointVO> tasks = _maidDao.listLeftoversByCutTime(_curDate, _msId);
tasks.addAll(_maidDao.listCleanupTasks(_msId));
List<CheckPointVO> retries = new ArrayList<CheckPointVO>();
for (CheckPointVO task : tasks) {
try {
if (!cleanup(task)) {
retries.add(task);
}
} catch (Exception e) {
s_logger.warn("Unable to clean up " + task, e);
}
}
if (retries.size() > 0) {
if (_cleanupRetryInterval > 0) {
_cleanupScheduler.schedule(this, _cleanupRetryInterval, TimeUnit.SECONDS);
} else {
for (CheckPointVO task : retries) {
s_logger.warn("Cleanup procedure for " + task + ": " + ((CleanupMaid)SerializerHelper.fromSerializedString(task.getContext())).getCleanupProcedure());
}
}
}
} catch (Exception e) {
s_logger.error("Unable to cleanup all of the tasks for " + _msId, e);
}
}
}
}

View File

@ -1,41 +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 com.cloud.cluster;
/**
*
* task. The state is serialized and stored. When cleanup is required
* CleanupMaid is instantiated from the stored data and cleanup() is called.
*
*/
public interface CleanupMaid {
/**
* cleanup according the state that was stored.
*
* @return 0 indicates cleanup was successful. Negative number
* indicates the cleanup was unsuccessful but don't retry. Positive number
* indicates the cleanup was unsuccessful and retry in this many seconds.
*/
int cleanup(CheckPointManager checkPointMgr);
/**
* returned here is recorded.
* @return
*/
String getCleanupProcedure();
}

View File

@ -29,7 +29,6 @@ import java.sql.SQLException;
import java.sql.SQLRecoverableException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -75,8 +74,6 @@ import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Profiler;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.ConnectionConcierge;
import com.cloud.utils.db.DB;
@ -150,9 +147,9 @@ public class ClusterManagerImpl implements ClusterManager {
private double _connectedAgentsThreshold = 0.7;
private static boolean _agentLbHappened = false;
private List<ClusterServicePdu> _clusterPduOutgoingQueue = new ArrayList<ClusterServicePdu>();
private List<ClusterServicePdu> _clusterPduIncomingQueue = new ArrayList<ClusterServicePdu>();
private Map<Long, ClusterServiceRequestPdu> _outgoingPdusWaitingForAck = new HashMap<Long, ClusterServiceRequestPdu>();
private final List<ClusterServicePdu> _clusterPduOutgoingQueue = new ArrayList<ClusterServicePdu>();
private final List<ClusterServicePdu> _clusterPduIncomingQueue = new ArrayList<ClusterServicePdu>();
private final Map<Long, ClusterServiceRequestPdu> _outgoingPdusWaitingForAck = new HashMap<Long, ClusterServiceRequestPdu>();
public ClusterManagerImpl() {
_clusterPeers = new HashMap<String, ClusterService>();
@ -205,53 +202,54 @@ public class ClusterManagerImpl implements ClusterManager {
}
private void addOutgoingClusterPdu(ClusterServicePdu pdu) {
synchronized(_clusterPduOutgoingQueue) {
_clusterPduOutgoingQueue.add(pdu);
_clusterPduOutgoingQueue.notifyAll();
}
synchronized(_clusterPduOutgoingQueue) {
_clusterPduOutgoingQueue.add(pdu);
_clusterPduOutgoingQueue.notifyAll();
}
}
private ClusterServicePdu popOutgoingClusterPdu(long timeoutMs) {
synchronized(_clusterPduOutgoingQueue) {
try {
_clusterPduOutgoingQueue.wait(timeoutMs);
} catch (InterruptedException e) {
}
synchronized(_clusterPduOutgoingQueue) {
try {
_clusterPduOutgoingQueue.wait(timeoutMs);
} catch (InterruptedException e) {
}
if(_clusterPduOutgoingQueue.size() > 0) {
ClusterServicePdu pdu = _clusterPduOutgoingQueue.get(0);
_clusterPduOutgoingQueue.remove(0);
return pdu;
}
}
return null;
if(_clusterPduOutgoingQueue.size() > 0) {
ClusterServicePdu pdu = _clusterPduOutgoingQueue.get(0);
_clusterPduOutgoingQueue.remove(0);
return pdu;
}
}
return null;
}
private void addIncomingClusterPdu(ClusterServicePdu pdu) {
synchronized(_clusterPduIncomingQueue) {
_clusterPduIncomingQueue.add(pdu);
_clusterPduIncomingQueue.notifyAll();
}
synchronized(_clusterPduIncomingQueue) {
_clusterPduIncomingQueue.add(pdu);
_clusterPduIncomingQueue.notifyAll();
}
}
private ClusterServicePdu popIncomingClusterPdu(long timeoutMs) {
synchronized(_clusterPduIncomingQueue) {
try {
_clusterPduIncomingQueue.wait(timeoutMs);
} catch (InterruptedException e) {
}
synchronized(_clusterPduIncomingQueue) {
try {
_clusterPduIncomingQueue.wait(timeoutMs);
} catch (InterruptedException e) {
}
if(_clusterPduIncomingQueue.size() > 0) {
ClusterServicePdu pdu = _clusterPduIncomingQueue.get(0);
_clusterPduIncomingQueue.remove(0);
return pdu;
}
}
return null;
if(_clusterPduIncomingQueue.size() > 0) {
ClusterServicePdu pdu = _clusterPduIncomingQueue.get(0);
_clusterPduIncomingQueue.remove(0);
return pdu;
}
}
return null;
}
private Runnable getClusterPduSendingTask() {
return new Runnable() {
@Override
public void run() {
onSendingClusterPdu();
}
@ -260,6 +258,7 @@ public class ClusterManagerImpl implements ClusterManager {
private Runnable getClusterPduNotificationTask() {
return new Runnable() {
@Override
public void run() {
onNotifyingClusterPdu();
}
@ -271,7 +270,7 @@ public class ClusterManagerImpl implements ClusterManager {
try {
ClusterServicePdu pdu = popOutgoingClusterPdu(1000);
if(pdu == null)
continue;
continue;
ClusterService peerService = null;
for(int i = 0; i < 2; i++) {
@ -285,15 +284,15 @@ public class ClusterManagerImpl implements ClusterManager {
try {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + ". agent: " + pdu.getAgentId()
+ ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage());
+ ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage());
}
long startTick = System.currentTimeMillis();
String strResult = peerService.execute(pdu);
if(s_logger.isDebugEnabled()) {
s_logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + " completed. time: " +
(System.currentTimeMillis() - startTick) + "ms. agent: " + pdu.getAgentId()
+ ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage());
(System.currentTimeMillis() - startTick) + "ms. agent: " + pdu.getAgentId()
+ ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage());
}
if("true".equals(strResult))
@ -319,37 +318,38 @@ public class ClusterManagerImpl implements ClusterManager {
try {
final ClusterServicePdu pdu = popIncomingClusterPdu(1000);
if(pdu == null)
continue;
continue;
_executor.execute(new Runnable() {
public void run() {
if(pdu.getPduType() == ClusterServicePdu.PDU_TYPE_RESPONSE) {
ClusterServiceRequestPdu requestPdu = popRequestPdu(pdu.getAckSequenceId());
if(requestPdu != null) {
requestPdu.setResponseResult(pdu.getJsonPackage());
synchronized(requestPdu) {
requestPdu.notifyAll();
}
} else {
s_logger.warn("Original request has already been cancelled. pdu: " + _gson.toJson(pdu));
}
} else {
String result = dispatchClusterServicePdu(pdu);
if(result == null)
result = "";
@Override
public void run() {
if(pdu.getPduType() == ClusterServicePdu.PDU_TYPE_RESPONSE) {
ClusterServiceRequestPdu requestPdu = popRequestPdu(pdu.getAckSequenceId());
if(requestPdu != null) {
requestPdu.setResponseResult(pdu.getJsonPackage());
synchronized(requestPdu) {
requestPdu.notifyAll();
}
} else {
s_logger.warn("Original request has already been cancelled. pdu: " + _gson.toJson(pdu));
}
} else {
String result = dispatchClusterServicePdu(pdu);
if(result == null)
result = "";
if(pdu.getPduType() == ClusterServicePdu.PDU_TYPE_REQUEST) {
ClusterServicePdu responsePdu = new ClusterServicePdu();
responsePdu.setPduType(ClusterServicePdu.PDU_TYPE_RESPONSE);
responsePdu.setSourcePeer(pdu.getDestPeer());
responsePdu.setDestPeer(pdu.getSourcePeer());
responsePdu.setAckSequenceId(pdu.getSequenceId());
responsePdu.setJsonPackage(result);
if(pdu.getPduType() == ClusterServicePdu.PDU_TYPE_REQUEST) {
ClusterServicePdu responsePdu = new ClusterServicePdu();
responsePdu.setPduType(ClusterServicePdu.PDU_TYPE_RESPONSE);
responsePdu.setSourcePeer(pdu.getDestPeer());
responsePdu.setDestPeer(pdu.getSourcePeer());
responsePdu.setAckSequenceId(pdu.getSequenceId());
responsePdu.setJsonPackage(result);
addOutgoingClusterPdu(responsePdu);
}
}
}
addOutgoingClusterPdu(responsePdu);
}
}
}
});
} catch(Throwable e) {
s_logger.error("Unexcpeted exception: ", e);
@ -416,22 +416,22 @@ public class ClusterManagerImpl implements ClusterManager {
answers[0] = new Answer(cmd, result, null);
return _gson.toJson(answers);
} else if (cmds.length == 1 && cmds[0] instanceof PropagateResourceEventCommand ) {
PropagateResourceEventCommand cmd = (PropagateResourceEventCommand) cmds[0];
PropagateResourceEventCommand cmd = (PropagateResourceEventCommand) cmds[0];
s_logger.debug("Intercepting command to propagate event " + cmd.getEvent().name() + " for host " + cmd.getHostId());
s_logger.debug("Intercepting command to propagate event " + cmd.getEvent().name() + " for host " + cmd.getHostId());
boolean result = false;
try {
result = executeResourceUserRequest(cmd.getHostId(), cmd.getEvent());
s_logger.debug("Result is " + result);
} catch (AgentUnavailableException ex) {
s_logger.warn("Agent is unavailable", ex);
return null;
}
boolean result = false;
try {
result = executeResourceUserRequest(cmd.getHostId(), cmd.getEvent());
s_logger.debug("Result is " + result);
} catch (AgentUnavailableException ex) {
s_logger.warn("Agent is unavailable", ex);
return null;
}
Answer[] answers = new Answer[1];
answers[0] = new Answer(cmd, result, null);
return _gson.toJson(answers);
Answer[] answers = new Answer[1];
answers[0] = new Answer(cmd, result, null);
return _gson.toJson(answers);
}
try {
@ -465,8 +465,9 @@ public class ClusterManagerImpl implements ClusterManager {
return null;
}
@Override
public void OnReceiveClusterServicePdu(ClusterServicePdu pdu) {
addIncomingClusterPdu(pdu);
addIncomingClusterPdu(pdu);
}
@Override
@ -577,7 +578,7 @@ public class ClusterManagerImpl implements ClusterManager {
if(s_logger.isDebugEnabled()) {
s_logger.debug(getSelfPeerName() + " -> " + strPeer + "." + agentId + " completed. result: " +
pdu.getResponseResult());
pdu.getResponseResult());
}
if(pdu.getResponseResult() != null && pdu.getResponseResult().length() > 0) {
@ -625,18 +626,18 @@ public class ClusterManagerImpl implements ClusterManager {
// Note : we don't check duplicates
synchronized (_listeners) {
s_logger.info("register cluster listener " + listener.getClass());
s_logger.info("register cluster listener " + listener.getClass());
_listeners.add(listener);
_listeners.add(listener);
}
}
@Override
public void unregisterListener(ClusterManagerListener listener) {
synchronized(_listeners) {
s_logger.info("unregister cluster listener " + listener.getClass());
s_logger.info("unregister cluster listener " + listener.getClass());
_listeners.remove(listener);
_listeners.remove(listener);
}
}
@ -788,9 +789,9 @@ public class ClusterManagerImpl implements ClusterManager {
if(profiler.getDuration() >= _heartbeatInterval) {
if(s_logger.isDebugEnabled())
s_logger.debug("Management server heartbeat takes too long to finish. profiler: " + profiler.toString() +
", profilerHeartbeatUpdate: " + profilerHeartbeatUpdate.toString() +
", profilerPeerScan: " + profilerPeerScan.toString() +
", profilerAgentLB: " + profilerAgentLB.toString());
", profilerHeartbeatUpdate: " + profilerHeartbeatUpdate.toString() +
", profilerPeerScan: " + profilerPeerScan.toString() +
", profilerAgentLB: " + profilerAgentLB.toString());
}
}
@ -936,26 +937,26 @@ public class ClusterManagerImpl implements ClusterManager {
switch(msg.getMessageType()) {
case nodeAdded:
{
List<ManagementServerHostVO> l = msg.getNodes();
if(l != null && l.size() > 0) {
for(ManagementServerHostVO mshost: l) {
_mshostPeerDao.updatePeerInfo(_mshostId, mshost.getId(), mshost.getRunid(), ManagementServerHost.State.Up);
}
{
List<ManagementServerHostVO> l = msg.getNodes();
if(l != null && l.size() > 0) {
for(ManagementServerHostVO mshost: l) {
_mshostPeerDao.updatePeerInfo(_mshostId, mshost.getId(), mshost.getRunid(), ManagementServerHost.State.Up);
}
}
break;
}
break;
case nodeRemoved:
{
List<ManagementServerHostVO> l = msg.getNodes();
if(l != null && l.size() > 0) {
for(ManagementServerHostVO mshost: l) {
_mshostPeerDao.updatePeerInfo(_mshostId, mshost.getId(), mshost.getRunid(), ManagementServerHost.State.Down);
}
{
List<ManagementServerHostVO> l = msg.getNodes();
if(l != null && l.size() > 0) {
for(ManagementServerHostVO mshost: l) {
_mshostPeerDao.updatePeerInfo(_mshostId, mshost.getId(), mshost.getRunid(), ManagementServerHost.State.Down);
}
}
break;
}
break;
default :
break;
@ -983,34 +984,34 @@ public class ClusterManagerImpl implements ClusterManager {
// remove records from mshost table, this will leave orphan mgmt_serve_id reference in host table.
List<Long> orphanList = _mshostDao.listOrphanMsids();
if(orphanList.size() > 0) {
for(Long orphanMsid : orphanList) {
// construct fake ManagementServerHostVO based on orphan MSID
s_logger.info("Add orphan management server msid found in host table to initial clustering notification, orphan msid: " + orphanMsid);
inactiveList.add(new ManagementServerHostVO(orphanMsid, 0, "orphan", 0, new Date()));
}
for(Long orphanMsid : orphanList) {
// construct fake ManagementServerHostVO based on orphan MSID
s_logger.info("Add orphan management server msid found in host table to initial clustering notification, orphan msid: " + orphanMsid);
inactiveList.add(new ManagementServerHostVO(orphanMsid, 0, "orphan", 0, new Date()));
}
} else {
s_logger.info("We are good, no orphan management server msid in host table is found");
s_logger.info("We are good, no orphan management server msid in host table is found");
}
if(inactiveList.size() > 0) {
if(s_logger.isInfoEnabled()) {
s_logger.info("Found " + inactiveList.size() + " inactive management server node based on timestamp");
for(ManagementServerHostVO host : inactiveList)
s_logger.info("management server node msid: " + host.getMsid() + ", name: " + host.getName() + ", service ip: " + host.getServiceIP() + ", version: " + host.getVersion());
}
if(s_logger.isInfoEnabled()) {
s_logger.info("Found " + inactiveList.size() + " inactive management server node based on timestamp");
for(ManagementServerHostVO host : inactiveList)
s_logger.info("management server node msid: " + host.getMsid() + ", name: " + host.getName() + ", service ip: " + host.getServiceIP() + ", version: " + host.getVersion());
}
List<ManagementServerHostVO> downHostList = new ArrayList<ManagementServerHostVO>();
List<ManagementServerHostVO> downHostList = new ArrayList<ManagementServerHostVO>();
for(ManagementServerHostVO host : inactiveList) {
if(!pingManagementNode(host)) {
s_logger.warn("Management node " + host.getId() + " is detected inactive by timestamp and also not pingable");
downHostList.add(host);
}
if(!pingManagementNode(host)) {
s_logger.warn("Management node " + host.getId() + " is detected inactive by timestamp and also not pingable");
downHostList.add(host);
}
}
if(downHostList.size() > 0)
this.queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeRemoved, downHostList));
this.queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeRemoved, downHostList));
} else {
s_logger.info("No inactive management server node found");
s_logger.info("No inactive management server node found");
}
}
@ -1140,10 +1141,10 @@ public class ClusterManagerImpl implements ClusterManager {
if(profiler.getDuration() >= this._heartbeatInterval) {
if(s_logger.isDebugEnabled())
s_logger.debug("Peer scan takes too long to finish. profiler: " + profiler.toString()
+ ", profilerQueryActiveList: " + profilerQueryActiveList.toString()
+ ", profilerSyncClusterInfo: " + profilerSyncClusterInfo.toString()
+ ", profilerInvalidatedNodeList: " + profilerInvalidatedNodeList.toString()
+ ", profilerRemovedList: " + profilerRemovedList.toString());
+ ", profilerQueryActiveList: " + profilerQueryActiveList.toString()
+ ", profilerSyncClusterInfo: " + profilerSyncClusterInfo.toString()
+ ", profilerInvalidatedNodeList: " + profilerInvalidatedNodeList.toString()
+ ", profilerRemovedList: " + profilerRemovedList.toString());
}
}
@ -1294,7 +1295,7 @@ public class ClusterManagerImpl implements ClusterManager {
}
for(int i = 0; i < DEFAULT_OUTGOING_WORKERS; i++)
_executor.execute(getClusterPduSendingTask());
_executor.execute(getClusterPduSendingTask());
// notification task itself in turn works as a task dispatcher
_executor.execute(getClusterPduNotificationTask());
@ -1381,7 +1382,7 @@ public class ClusterManagerImpl implements ClusterManager {
} catch (IOException e) {
if (e instanceof ConnectException) {
s_logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException", e);
return false;
return false;
}
} finally {
if (sch != null) {

View File

@ -1,153 +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 com.cloud.cluster;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.cluster.dao.StackMaidDao;
import com.cloud.cluster.dao.StackMaidDaoImpl;
import com.cloud.serializer.SerializerHelper;
import com.cloud.utils.CleanupDelegate;
import com.cloud.utils.db.Transaction;
public class StackMaid {
protected final static Logger s_logger = Logger.getLogger(StackMaid.class);
private static ThreadLocal<StackMaid> threadMaid = new ThreadLocal<StackMaid>();
private static long msid_setby_manager = 0;
private StackMaidDao maidDao = new StackMaidDaoImpl();
private int currentSeq = 0;
private Map<String, Object> context = new HashMap<String, Object>();
public static void init(long msid) {
msid_setby_manager = msid;
}
public static StackMaid current() {
StackMaid maid = threadMaid.get();
if(maid == null) {
maid = new StackMaid();
threadMaid.set(maid);
}
return maid;
}
public void registerContext(String key, Object contextObject) {
assert(!context.containsKey(key)) : "Context key has already been registered";
context.put(key, contextObject);
}
public Object getContext(String key) {
return context.get(key);
}
public void expungeMaidItem(long maidId) {
// this is a bit ugly, but when it is not loaded by component locator, this is just a workable way for now
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
try {
maidDao.expunge(maidId);
} finally {
txn.close();
}
}
public int push(String delegateClzName, Object context) {
assert(msid_setby_manager != 0) : "Fatal, make sure StackMaidManager is loaded";
if(msid_setby_manager == 0)
s_logger.error("Fatal, make sure StackMaidManager is loaded");
return push(msid_setby_manager, delegateClzName, context);
}
public int push(long currentMsid, String delegateClzName, Object context) {
int savePoint = currentSeq;
maidDao.pushCleanupDelegate(currentMsid, currentSeq++, delegateClzName, context);
return savePoint;
}
public void pop(int savePoint) {
assert(msid_setby_manager != 0) : "Fatal, make sure StackMaidManager is loaded";
if(msid_setby_manager == 0)
s_logger.error("Fatal, make sure StackMaidManager is loaded");
pop(msid_setby_manager, savePoint);
}
public void pop() {
if(currentSeq > 0)
pop(currentSeq -1);
}
/**
* must be called within thread context
* @param currentMsid
*/
public void pop(long currentMsid, int savePoint) {
while(currentSeq > savePoint) {
maidDao.popCleanupDelegate(currentMsid);
currentSeq--;
}
}
public void exitCleanup() {
exitCleanup(msid_setby_manager);
}
public void exitCleanup(long currentMsid) {
if(currentSeq > 0) {
CheckPointVO maid = null;
while((maid = maidDao.popCleanupDelegate(currentMsid)) != null) {
doCleanup(maid);
}
currentSeq = 0;
}
context.clear();
}
public static boolean doCleanup(CheckPointVO maid) {
if(maid.getDelegate() != null) {
try {
Class<?> clz = Class.forName(maid.getDelegate());
Object delegate = clz.newInstance();
if(delegate instanceof CleanupDelegate) {
return ((CleanupDelegate)delegate).cleanup(SerializerHelper.fromSerializedString(maid.getContext()), maid);
} else {
assert(false);
}
} catch (final ClassNotFoundException e) {
s_logger.error("Unable to load StackMaid delegate class: " + maid.getDelegate(), e);
} catch (final SecurityException e) {
s_logger.error("Security excetion when loading resource: " + maid.getDelegate());
} catch (final IllegalArgumentException e) {
s_logger.error("Illegal argument excetion when loading resource: " + maid.getDelegate());
} catch (final InstantiationException e) {
s_logger.error("Instantiation excetion when loading resource: " + maid.getDelegate());
} catch (final IllegalAccessException e) {
s_logger.error("Illegal access exception when loading resource: " + maid.getDelegate());
}
return false;
}
return true;
}
}

View File

@ -34,7 +34,6 @@ import com.cloud.configuration.ResourceLimit;
import com.cloud.domain.dao.DomainDaoImpl;
import com.cloud.exception.UnsupportedServiceException;
import com.cloud.user.dao.AccountDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
@ -44,90 +43,90 @@ import com.cloud.utils.db.Transaction;
@Component
@Local(value={ResourceCountDao.class})
public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long> implements ResourceCountDao {
private SearchBuilder<ResourceCountVO> TypeSearch;
private final SearchBuilder<ResourceCountVO> TypeSearch;
private SearchBuilder<ResourceCountVO> AccountSearch;
private SearchBuilder<ResourceCountVO> DomainSearch;
private final SearchBuilder<ResourceCountVO> AccountSearch;
private final SearchBuilder<ResourceCountVO> DomainSearch;
//protected final DomainDaoImpl _domainDao = ComponentLocator.inject(DomainDaoImpl.class);
//protected final AccountDaoImpl _accountDao = ComponentLocator.inject(AccountDaoImpl.class);
//protected final DomainDaoImpl _domainDao = ComponentLocator.inject(DomainDaoImpl.class);
//protected final AccountDaoImpl _accountDao = ComponentLocator.inject(AccountDaoImpl.class);
@Inject protected DomainDaoImpl _domainDao;
@Inject protected AccountDaoImpl _accountDao;
@Inject protected DomainDaoImpl _domainDao;
@Inject protected AccountDaoImpl _accountDao;
public ResourceCountDaoImpl() {
TypeSearch = createSearchBuilder();
TypeSearch.and("type", TypeSearch.entity().getType(), SearchCriteria.Op.EQ);
TypeSearch.and("accountId", TypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
TypeSearch.and("domainId", TypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
TypeSearch.done();
public ResourceCountDaoImpl() {
TypeSearch = createSearchBuilder();
TypeSearch.and("type", TypeSearch.entity().getType(), SearchCriteria.Op.EQ);
TypeSearch.and("accountId", TypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
TypeSearch.and("domainId", TypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
TypeSearch.done();
AccountSearch = createSearchBuilder();
AccountSearch.and("accountId", AccountSearch.entity().getAccountId(), SearchCriteria.Op.NNULL);
AccountSearch.done();
AccountSearch = createSearchBuilder();
AccountSearch.and("accountId", AccountSearch.entity().getAccountId(), SearchCriteria.Op.NNULL);
AccountSearch.done();
DomainSearch = createSearchBuilder();
DomainSearch.and("domainId", DomainSearch.entity().getDomainId(), SearchCriteria.Op.NNULL);
DomainSearch.done();
}
DomainSearch = createSearchBuilder();
DomainSearch.and("domainId", DomainSearch.entity().getDomainId(), SearchCriteria.Op.NNULL);
DomainSearch.done();
}
@Override
public ResourceCountVO findByOwnerAndType(long ownerId, ResourceOwnerType ownerType, ResourceType type) {
SearchCriteria<ResourceCountVO> sc = TypeSearch.create();
sc.setParameters("type", type);
@Override
public ResourceCountVO findByOwnerAndType(long ownerId, ResourceOwnerType ownerType, ResourceType type) {
SearchCriteria<ResourceCountVO> sc = TypeSearch.create();
sc.setParameters("type", type);
if (ownerType == ResourceOwnerType.Account) {
sc.setParameters("accountId", ownerId);
return findOneIncludingRemovedBy(sc);
} else if (ownerType == ResourceOwnerType.Domain) {
sc.setParameters("domainId", ownerId);
if (ownerType == ResourceOwnerType.Account) {
sc.setParameters("accountId", ownerId);
return findOneIncludingRemovedBy(sc);
} else {
return null;
}
}
} else if (ownerType == ResourceOwnerType.Domain) {
sc.setParameters("domainId", ownerId);
return findOneIncludingRemovedBy(sc);
} else {
return null;
}
}
@Override
public long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type) {
ResourceCountVO vo = findByOwnerAndType(ownerId, ownerType, type);
if (vo != null) {
return vo.getCount();
} else {
return 0;
}
}
@Override
public long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type) {
ResourceCountVO vo = findByOwnerAndType(ownerId, ownerType, type);
if (vo != null) {
return vo.getCount();
} else {
return 0;
}
}
@Override
public void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, long count) {
ResourceCountVO resourceCountVO = findByOwnerAndType(ownerId, ownerType, type);
@Override
public void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, long count) {
ResourceCountVO resourceCountVO = findByOwnerAndType(ownerId, ownerType, type);
if (count != resourceCountVO.getCount()) {
resourceCountVO.setCount(count);
update(resourceCountVO.getId(), resourceCountVO);
}
}
}
@Override @Deprecated
public void updateDomainCount(long domainId, ResourceType type, boolean increment, long delta) {
delta = increment ? delta : delta * -1;
@Override @Deprecated
public void updateDomainCount(long domainId, ResourceType type, boolean increment, long delta) {
delta = increment ? delta : delta * -1;
ResourceCountVO resourceCountVO = findByOwnerAndType(domainId, ResourceOwnerType.Domain, type);
resourceCountVO.setCount(resourceCountVO.getCount() + delta);
update(resourceCountVO.getId(), resourceCountVO);
}
resourceCountVO.setCount(resourceCountVO.getCount() + delta);
update(resourceCountVO.getId(), resourceCountVO);
}
@Override
public boolean updateById(long id, boolean increment, long delta) {
delta = increment ? delta : delta * -1;
@Override
public boolean updateById(long id, boolean increment, long delta) {
delta = increment ? delta : delta * -1;
ResourceCountVO resourceCountVO = findById(id);
resourceCountVO.setCount(resourceCountVO.getCount() + delta);
return update(resourceCountVO.getId(), resourceCountVO);
}
ResourceCountVO resourceCountVO = findById(id);
resourceCountVO.setCount(resourceCountVO.getCount() + delta);
return update(resourceCountVO.getId(), resourceCountVO);
}
@Override
public Set<Long> listRowsToUpdateForDomain(long domainId, ResourceType type) {
Set<Long> rowIds = new HashSet<Long>();
Set<Long> domainIdsToUpdate = _domainDao.getDomainParentIds(domainId);
@Override
public Set<Long> listRowsToUpdateForDomain(long domainId, ResourceType type) {
Set<Long> rowIds = new HashSet<Long>();
Set<Long> domainIdsToUpdate = _domainDao.getDomainParentIds(domainId);
for (Long domainIdToUpdate : domainIdsToUpdate) {
ResourceCountVO domainCountRecord = findByOwnerAndType(domainIdToUpdate, ResourceOwnerType.Domain, type);
if (domainCountRecord != null) {
@ -135,29 +134,29 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
}
}
return rowIds;
}
}
@Override
public Set<Long> listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type) {
Set<Long> rowIds = new HashSet<Long>();
@Override
public Set<Long> listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type) {
Set<Long> rowIds = new HashSet<Long>();
if (ownerType == ResourceOwnerType.Account) {
//get records for account
ResourceCountVO accountCountRecord = findByOwnerAndType(ownerId, ResourceOwnerType.Account, type);
if (accountCountRecord != null) {
rowIds.add(accountCountRecord.getId());
}
if (ownerType == ResourceOwnerType.Account) {
//get records for account
ResourceCountVO accountCountRecord = findByOwnerAndType(ownerId, ResourceOwnerType.Account, type);
if (accountCountRecord != null) {
rowIds.add(accountCountRecord.getId());
}
//get records for account's domain and all its parent domains
rowIds.addAll(listRowsToUpdateForDomain(_accountDao.findByIdIncludingRemoved(ownerId).getDomainId(),type));
} else if (ownerType == ResourceOwnerType.Domain) {
return listRowsToUpdateForDomain(ownerId, type);
}
//get records for account's domain and all its parent domains
rowIds.addAll(listRowsToUpdateForDomain(_accountDao.findByIdIncludingRemoved(ownerId).getDomainId(),type));
} else if (ownerType == ResourceOwnerType.Domain) {
return listRowsToUpdateForDomain(ownerId, type);
}
return rowIds;
}
return rowIds;
}
@Override @DB
@Override @DB
public void createResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType ownerType){
Transaction txn = Transaction.currentTxn();
@ -175,19 +174,19 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
txn.commit();
}
private List<ResourceCountVO> listByDomainId(long domainId) {
SearchCriteria<ResourceCountVO> sc = TypeSearch.create();
private List<ResourceCountVO> listByDomainId(long domainId) {
SearchCriteria<ResourceCountVO> sc = TypeSearch.create();
sc.setParameters("domainId", domainId);
return listBy(sc);
}
}
private List<ResourceCountVO> listByAccountId(long accountId) {
SearchCriteria<ResourceCountVO> sc = TypeSearch.create();
SearchCriteria<ResourceCountVO> sc = TypeSearch.create();
sc.setParameters("accountId", accountId);
return listBy(sc);
}
}
@Override
public List<ResourceCountVO> listByOwnerId(long ownerId, ResourceOwnerType ownerType) {
@ -200,24 +199,24 @@ public class ResourceCountDaoImpl extends GenericDaoBase<ResourceCountVO, Long>
}
}
@Override
public List<ResourceCountVO> listResourceCountByOwnerType(ResourceOwnerType ownerType) {
if (ownerType == ResourceOwnerType.Account) {
return listBy(AccountSearch.create());
} else if (ownerType == ResourceOwnerType.Domain) {
return listBy(DomainSearch.create());
} else {
return new ArrayList<ResourceCountVO>();
}
}
@Override
public List<ResourceCountVO> listResourceCountByOwnerType(ResourceOwnerType ownerType) {
if (ownerType == ResourceOwnerType.Account) {
return listBy(AccountSearch.create());
} else if (ownerType == ResourceOwnerType.Domain) {
return listBy(DomainSearch.create());
} else {
return new ArrayList<ResourceCountVO>();
}
}
@Override
@Override
public ResourceCountVO persist(ResourceCountVO resourceCountVO){
ResourceOwnerType ownerType = resourceCountVO.getResourceOwnerType();
ResourceType resourceType = resourceCountVO.getType();
if (!resourceType.supportsOwner(ownerType)) {
throw new UnsupportedServiceException("Resource type " + resourceType + " is not supported for owner of type " + ownerType.getName());
}
ResourceOwnerType ownerType = resourceCountVO.getResourceOwnerType();
ResourceType resourceType = resourceCountVO.getType();
if (!resourceType.supportsOwner(ownerType)) {
throw new UnsupportedServiceException("Resource type " + resourceType + " is not supported for owner of type " + ownerType.getName());
}
return super.persist(resourceCountVO);
}

View File

@ -49,7 +49,6 @@ import com.cloud.host.dao.HostDao;
import com.cloud.info.ConsoleProxyInfo;
import com.cloud.network.Network;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.UserVmVO;
@ -276,7 +275,7 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu
@Override
public ConsoleProxyManagementState getManagementState() {
return null;
return null;
}
@Override

View File

@ -27,9 +27,6 @@ import javax.naming.ConfigurationException;
import org.springframework.stereotype.Component;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.ConsoleProxyVO;
import edu.emory.mathcs.backport.java.util.Collections;
@ -42,40 +39,40 @@ public class ConsoleProxyBalanceAllocator implements ConsoleProxyAllocator {
private final Random _rand = new Random(System.currentTimeMillis());
@Override
public ConsoleProxyVO allocProxy(List<ConsoleProxyVO> candidates, final Map<Long, Integer> loadInfo, long dataCenterId) {
if(candidates != null) {
public ConsoleProxyVO allocProxy(List<ConsoleProxyVO> candidates, final Map<Long, Integer> loadInfo, long dataCenterId) {
if(candidates != null) {
List<ConsoleProxyVO> allocationList = new ArrayList<ConsoleProxyVO>();
for(ConsoleProxyVO proxy : candidates) {
allocationList.add(proxy);
}
List<ConsoleProxyVO> allocationList = new ArrayList<ConsoleProxyVO>();
for(ConsoleProxyVO proxy : candidates) {
allocationList.add(proxy);
}
Collections.sort(candidates, new Comparator<ConsoleProxyVO> () {
@Override
public int compare(ConsoleProxyVO x, ConsoleProxyVO y) {
Integer loadOfX = loadInfo.get(x.getId());
Integer loadOfY = loadInfo.get(y.getId());
Collections.sort(candidates, new Comparator<ConsoleProxyVO> () {
@Override
public int compare(ConsoleProxyVO x, ConsoleProxyVO y) {
Integer loadOfX = loadInfo.get(x.getId());
Integer loadOfY = loadInfo.get(y.getId());
if(loadOfX != null && loadOfY != null) {
if(loadOfX < loadOfY)
return -1;
else if(loadOfX > loadOfY)
return 1;
return 0;
} else if(loadOfX == null && loadOfY == null) {
return 0;
} else {
if(loadOfX == null)
return -1;
return 1;
}
}
});
if(loadOfX != null && loadOfY != null) {
if(loadOfX < loadOfY)
return -1;
else if(loadOfX > loadOfY)
return 1;
return 0;
} else if(loadOfX == null && loadOfY == null) {
return 0;
} else {
if(loadOfX == null)
return -1;
return 1;
}
}
});
if(allocationList.size() > 0)
return allocationList.get(0);
}
return null;
if(allocationList.size() > 0)
return allocationList.get(0);
}
return null;
}
@Override

View File

@ -19,7 +19,6 @@ package com.cloud.consoleproxy;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -32,6 +31,7 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import javax.persistence.Table;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
@ -55,7 +55,6 @@ import com.cloud.agent.api.proxy.StartConsoleProxyAgentHttpHandlerCommand;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import org.apache.cloudstack.api.ServerApiException;
import com.cloud.api.commands.DestroyConsoleProxyCmd;
import com.cloud.certificate.dao.CertificateDao;
import com.cloud.cluster.ClusterManager;
@ -128,8 +127,6 @@ import com.cloud.utils.DateUtil;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GlobalLock;
@ -478,9 +475,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
assert (ksVo != null);
if (_staticPublicIp == null) {
return new ConsoleProxyInfo(proxy.isSslEnabled(), proxy.getPublicIpAddress(), _consoleProxyPort, proxy.getPort(), ksVo.getDomainSuffix());
return new ConsoleProxyInfo(proxy.isSslEnabled(), proxy.getPublicIpAddress(), _consoleProxyPort, proxy.getPort(), ksVo.getDomainSuffix());
} else {
return new ConsoleProxyInfo(proxy.isSslEnabled(), _staticPublicIp, _consoleProxyPort, _staticPort, ksVo.getDomainSuffix());
return new ConsoleProxyInfo(proxy.isSslEnabled(), _staticPublicIp, _consoleProxyPort, _staticPort, ksVo.getDomainSuffix());
}
}
@ -809,9 +806,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
private ConsoleProxyAllocator getCurrentAllocator() {
// for now, only one adapter is supported
for(ConsoleProxyAllocator allocator : _consoleProxyAllocators) {
return allocator;
}
for(ConsoleProxyAllocator allocator : _consoleProxyAllocators) {
return allocator;
}
return null;
}
@ -903,26 +900,26 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
}
if(!cmd.isReauthenticating()) {
String ticket = ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console authentication. Ticket in 1 minute boundary for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + ticket);
}
String ticket = ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console authentication. Ticket in 1 minute boundary for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + ticket);
}
if (!ticket.equals(ticketInUrl)) {
Date now = new Date();
// considering of minute round-up
String minuteEarlyTicket = ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId(), new Date(now.getTime() - 60 * 1000));
if (!ticket.equals(ticketInUrl)) {
Date now = new Date();
// considering of minute round-up
String minuteEarlyTicket = ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId(), new Date(now.getTime() - 60 * 1000));
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console authentication. Ticket in 2-minute boundary for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + minuteEarlyTicket);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console authentication. Ticket in 2-minute boundary for " + cmd.getHost() + ":" + cmd.getPort() + "-" + cmd.getVmId() + " is " + minuteEarlyTicket);
}
if (!minuteEarlyTicket.equals(ticketInUrl)) {
s_logger.error("Access ticket expired or has been modified. vmId: " + cmd.getVmId() + "ticket in URL: " + ticketInUrl + ", tickets to check against: " + ticket + ","
+ minuteEarlyTicket);
return new ConsoleAccessAuthenticationAnswer(cmd, false);
}
}
if (!minuteEarlyTicket.equals(ticketInUrl)) {
s_logger.error("Access ticket expired or has been modified. vmId: " + cmd.getVmId() + "ticket in URL: " + ticketInUrl + ", tickets to check against: " + ticket + ","
+ minuteEarlyTicket);
return new ConsoleAccessAuthenticationAnswer(cmd, false);
}
}
}
if (cmd.getVmId() != null && cmd.getVmId().isEmpty()) {
@ -965,30 +962,30 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
authenticationAnswer.setReauthenticating(true);
s_logger.info("Re-authentication request, ask host " + vm.getHostId() + " for new console info");
GetVncPortAnswer answer = (GetVncPortAnswer) _agentMgr.easySend(vm.getHostId(), new
GetVncPortCommand(vm.getId(), vm.getInstanceName()));
GetVncPortAnswer answer = (GetVncPortAnswer) _agentMgr.easySend(vm.getHostId(), new
GetVncPortCommand(vm.getId(), vm.getInstanceName()));
if (answer != null && answer.getResult()) {
Ternary<String, String, String> parsedHostInfo = ConsoleProxyServlet.parseHostInfo(answer.getAddress());
Ternary<String, String, String> parsedHostInfo = ConsoleProxyServlet.parseHostInfo(answer.getAddress());
if(parsedHostInfo.second() != null && parsedHostInfo.third() != null) {
if(parsedHostInfo.second() != null && parsedHostInfo.third() != null) {
s_logger.info("Re-authentication result. vm: " + vm.getId() + ", tunnel url: " + parsedHostInfo.second()
+ ", tunnel session: " + parsedHostInfo.third());
+ ", tunnel session: " + parsedHostInfo.third());
authenticationAnswer.setTunnelUrl(parsedHostInfo.second());
authenticationAnswer.setTunnelSession(parsedHostInfo.third());
} else {
authenticationAnswer.setTunnelUrl(parsedHostInfo.second());
authenticationAnswer.setTunnelSession(parsedHostInfo.third());
} else {
s_logger.info("Re-authentication result. vm: " + vm.getId() + ", host address: " + parsedHostInfo.first()
+ ", port: " + answer.getPort());
+ ", port: " + answer.getPort());
authenticationAnswer.setHost(parsedHostInfo.first());
authenticationAnswer.setPort(answer.getPort());
}
authenticationAnswer.setHost(parsedHostInfo.first());
authenticationAnswer.setPort(answer.getPort());
}
} else {
s_logger.warn("Re-authentication request failed");
authenticationAnswer.setSuccess(false);
authenticationAnswer.setSuccess(false);
}
return authenticationAnswer;
@ -1198,11 +1195,11 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
}
} else {
if (s_logger.isDebugEnabled()) {
if (secondaryStorageHost != null) {
s_logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage: " + secondaryStorageHost.getId());
} else {
s_logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage.");
}
if (secondaryStorageHost != null) {
s_logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage: " + secondaryStorageHost.getId());
} else {
s_logger.debug("Zone host is ready, but console proxy template: " + template.getId() + " is not ready on secondary storage.");
}
}
}
}
@ -1532,8 +1529,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
}
if(_serviceOffering == null || !_serviceOffering.getSystemUse()){
int ramSize = NumbersUtil.parseInt(_configDao.getValue("console.ram.size"), DEFAULT_PROXY_VM_RAMSIZE);
int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("console.cpu.mhz"), DEFAULT_PROXY_VM_CPUMHZ);
int ramSize = NumbersUtil.parseInt(_configDao.getValue("console.ram.size"), DEFAULT_PROXY_VM_RAMSIZE);
int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("console.cpu.mhz"), DEFAULT_PROXY_VM_CPUMHZ);
_serviceOffering = new ServiceOfferingVO("System Offering For Console Proxy", 1, ramSize, cpuFreq, 0, 0, false, null, useLocalStorage, true, null, true, VirtualMachine.Type.ConsoleProxy, true);
_serviceOffering.setUniqueName(ServiceOffering.consoleProxyDefaultOffUniqueName);
_serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering);
@ -1552,7 +1549,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
_staticPublicIp = _configDao.getValue("consoleproxy.static.publicIp");
if (_staticPublicIp != null) {
_staticPort = NumbersUtil.parseInt(_configDao.getValue("consoleproxy.static.port"), 8443);
_staticPort = NumbersUtil.parseInt(_configDao.getValue("consoleproxy.static.port"), 8443);
}
if (s_logger.isInfoEnabled()) {
@ -2037,7 +2034,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
}
@Override
public void prepareStop(VirtualMachineProfile<ConsoleProxyVO> profile) {
}
@Override
public void prepareStop(VirtualMachineProfile<ConsoleProxyVO> profile) {
}
}

View File

@ -30,7 +30,6 @@ import com.cloud.host.Host.Type;
import com.cloud.host.HostVO;
import com.cloud.info.ConsoleProxyInfo;
import com.cloud.resource.ResourceManager;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.dao.ConsoleProxyDao;

View File

@ -33,7 +33,6 @@ import com.cloud.dc.ClusterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.org.Grouping;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.JoinBuilder;
@ -145,7 +144,7 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
@Override
public Map<Long, List<Long>> getPodClusterIdMap(List<Long> clusterIds){
Transaction txn = Transaction.currentTxn();
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
Map<Long, List<Long>> result = new HashMap<Long, List<Long>>();
@ -162,16 +161,16 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
pstmt = txn.prepareAutoCloseStatement(sql.toString());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Long podId = rs.getLong(1);
Long clusterIdInPod = rs.getLong(2);
Long podId = rs.getLong(1);
Long clusterIdInPod = rs.getLong(2);
if(result.containsKey(podId)){
List<Long> clusterList = result.get(podId);
clusterList.add(clusterIdInPod);
result.put(podId, clusterList);
List<Long> clusterList = result.get(podId);
clusterList.add(clusterIdInPod);
result.put(podId, clusterList);
}else{
List<Long> clusterList = new ArrayList<Long>();
clusterList.add(clusterIdInPod);
result.put(podId, clusterList);
List<Long> clusterList = new ArrayList<Long>();
clusterList.add(clusterIdInPod);
result.put(podId, clusterList);
}
}
return result;
@ -184,21 +183,21 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
@Override
public List<Long> listDisabledClusters(long zoneId, Long podId) {
GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
clusterIdSearch.selectField(clusterIdSearch.entity().getId());
clusterIdSearch.and("dataCenterId", clusterIdSearch.entity().getDataCenterId(), Op.EQ);
if(podId != null){
clusterIdSearch.and("podId", clusterIdSearch.entity().getPodId(), Op.EQ);
}
clusterIdSearch.and("allocationState", clusterIdSearch.entity().getAllocationState(), Op.EQ);
clusterIdSearch.done();
GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
clusterIdSearch.selectField(clusterIdSearch.entity().getId());
clusterIdSearch.and("dataCenterId", clusterIdSearch.entity().getDataCenterId(), Op.EQ);
if(podId != null){
clusterIdSearch.and("podId", clusterIdSearch.entity().getPodId(), Op.EQ);
}
clusterIdSearch.and("allocationState", clusterIdSearch.entity().getAllocationState(), Op.EQ);
clusterIdSearch.done();
SearchCriteria<Long> sc = clusterIdSearch.create();
SearchCriteria<Long> sc = clusterIdSearch.create();
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
if (podId != null) {
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
}
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
}
sc.addAnd("allocationState", SearchCriteria.Op.EQ, Grouping.AllocationState.Disabled);
return customSearch(sc, null);
}
@ -206,18 +205,18 @@ public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements C
@Override
public List<Long> listClustersWithDisabledPods(long zoneId) {
GenericSearchBuilder<HostPodVO, Long> disabledPodIdSearch = _hostPodDao.createSearchBuilder(Long.class);
disabledPodIdSearch.selectField(disabledPodIdSearch.entity().getId());
disabledPodIdSearch.and("dataCenterId", disabledPodIdSearch.entity().getDataCenterId(), Op.EQ);
disabledPodIdSearch.and("allocationState", disabledPodIdSearch.entity().getAllocationState(), Op.EQ);
GenericSearchBuilder<HostPodVO, Long> disabledPodIdSearch = _hostPodDao.createSearchBuilder(Long.class);
disabledPodIdSearch.selectField(disabledPodIdSearch.entity().getId());
disabledPodIdSearch.and("dataCenterId", disabledPodIdSearch.entity().getDataCenterId(), Op.EQ);
disabledPodIdSearch.and("allocationState", disabledPodIdSearch.entity().getAllocationState(), Op.EQ);
GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
clusterIdSearch.selectField(clusterIdSearch.entity().getId());
clusterIdSearch.join("disabledPodIdSearch", disabledPodIdSearch, clusterIdSearch.entity().getPodId(), disabledPodIdSearch.entity().getId(), JoinBuilder.JoinType.INNER);
clusterIdSearch.done();
GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
clusterIdSearch.selectField(clusterIdSearch.entity().getId());
clusterIdSearch.join("disabledPodIdSearch", disabledPodIdSearch, clusterIdSearch.entity().getPodId(), disabledPodIdSearch.entity().getId(), JoinBuilder.JoinType.INNER);
clusterIdSearch.done();
SearchCriteria<Long> sc = clusterIdSearch.create();
SearchCriteria<Long> sc = clusterIdSearch.create();
sc.setJoinParameters("disabledPodIdSearch", "dataCenterId", zoneId);
sc.setJoinParameters("disabledPodIdSearch", "allocationState", Grouping.AllocationState.Disabled);

View File

@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@ -37,7 +38,6 @@ import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.dao.VMInstanceDaoImpl;
@ -46,32 +46,32 @@ import com.cloud.vm.dao.VMInstanceDaoImpl;
@Local(value={HostPodDao.class})
public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements HostPodDao {
private static final Logger s_logger = Logger.getLogger(HostPodDaoImpl.class);
@Inject VMInstanceDaoImpl _vmDao;
protected SearchBuilder<HostPodVO> DataCenterAndNameSearch;
protected SearchBuilder<HostPodVO> DataCenterIdSearch;
protected SearchBuilder<HostPodVO> DataCenterAndNameSearch;
protected SearchBuilder<HostPodVO> DataCenterIdSearch;
protected HostPodDaoImpl() {
DataCenterAndNameSearch = createSearchBuilder();
DataCenterAndNameSearch.and("dc", DataCenterAndNameSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
DataCenterAndNameSearch.and("name", DataCenterAndNameSearch.entity().getName(), SearchCriteria.Op.EQ);
DataCenterAndNameSearch.done();
protected HostPodDaoImpl() {
DataCenterAndNameSearch = createSearchBuilder();
DataCenterAndNameSearch.and("dc", DataCenterAndNameSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
DataCenterAndNameSearch.and("name", DataCenterAndNameSearch.entity().getName(), SearchCriteria.Op.EQ);
DataCenterAndNameSearch.done();
DataCenterIdSearch = createSearchBuilder();
DataCenterIdSearch.and("dcId", DataCenterIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
DataCenterIdSearch.done();
}
DataCenterIdSearch = createSearchBuilder();
DataCenterIdSearch.and("dcId", DataCenterIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
DataCenterIdSearch.done();
}
@Override
@Override
public List<HostPodVO> listByDataCenterId(long id) {
SearchCriteria<HostPodVO> sc = DataCenterIdSearch.create();
sc.setParameters("dcId", id);
SearchCriteria<HostPodVO> sc = DataCenterIdSearch.create();
sc.setParameters("dcId", id);
return listBy(sc);
}
return listBy(sc);
}
@Override
@Override
public List<HostPodVO> listByDataCenterIdVMTypeAndStates(long id, VirtualMachine.Type type, VirtualMachine.State... states) {
final VMInstanceDaoImpl _vmDao = ComponentLocator.inject(VMInstanceDaoImpl.class);
SearchBuilder<VMInstanceVO> vmInstanceSearch = _vmDao.createSearchBuilder();
vmInstanceSearch.and("type", vmInstanceSearch.entity().getType(), SearchCriteria.Op.EQ);
vmInstanceSearch.and("states", vmInstanceSearch.entity().getState(), SearchCriteria.Op.IN);
@ -90,43 +90,43 @@ public class HostPodDaoImpl extends GenericDaoBase<HostPodVO, Long> implements H
return listBy(sc);
}
@Override
@Override
public HostPodVO findByName(String name, long dcId) {
SearchCriteria<HostPodVO> sc = DataCenterAndNameSearch.create();
sc.setParameters("dc", dcId);
sc.setParameters("name", name);
SearchCriteria<HostPodVO> sc = DataCenterAndNameSearch.create();
sc.setParameters("dc", dcId);
sc.setParameters("name", name);
return findOneBy(sc);
}
return findOneBy(sc);
}
@Override
public HashMap<Long, List<Object>> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip) {
HashMap<Long, List<Object>> currentPodCidrSubnets = new HashMap<Long, List<Object>>();
@Override
public HashMap<Long, List<Object>> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip) {
HashMap<Long, List<Object>> currentPodCidrSubnets = new HashMap<Long, List<Object>>();
String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + zoneId +" and removed IS NULL";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
Long podId = rs.getLong("id");
if (podId.longValue() == podIdToSkip) {
String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + zoneId +" and removed IS NULL";
Transaction txn = Transaction.currentTxn();
try {
PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
Long podId = rs.getLong("id");
if (podId.longValue() == podIdToSkip) {
continue;
}
String cidrAddress = rs.getString("cidr_address");
long cidrSize = rs.getLong("cidr_size");
List<Object> cidrPair = new ArrayList<Object>();
cidrPair.add(0, cidrAddress);
cidrPair.add(1, new Long(cidrSize));
currentPodCidrSubnets.put(podId, cidrPair);
}
String cidrAddress = rs.getString("cidr_address");
long cidrSize = rs.getLong("cidr_size");
List<Object> cidrPair = new ArrayList<Object>();
cidrPair.add(0, cidrAddress);
cidrPair.add(1, new Long(cidrSize));
currentPodCidrSubnets.put(podId, cidrPair);
}
} catch (SQLException ex) {
s_logger.warn("DB exception " + ex.getMessage(), ex);
s_logger.warn("DB exception " + ex.getMessage(), ex);
return null;
}
return currentPodCidrSubnets;
}
}
@Override
public boolean remove(Long id) {

View File

@ -36,7 +36,6 @@ import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.VlanVO;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.JoinBuilder;
@ -49,39 +48,39 @@ import com.cloud.utils.exception.CloudRuntimeException;
@Local(value={VlanDao.class})
public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao {
private final String FindZoneWideVlans = "SELECT * FROM vlan WHERE data_center_id=? and vlan_type=? and vlan_id!=? and id not in (select vlan_db_id from account_vlan_map)";
private final String FindZoneWideVlans = "SELECT * FROM vlan WHERE data_center_id=? and vlan_type=? and vlan_id!=? and id not in (select vlan_db_id from account_vlan_map)";
protected SearchBuilder<VlanVO> ZoneVlanIdSearch;
protected SearchBuilder<VlanVO> ZoneSearch;
protected SearchBuilder<VlanVO> ZoneTypeSearch;
protected SearchBuilder<VlanVO> ZoneTypeAllPodsSearch;
protected SearchBuilder<VlanVO> ZoneTypePodSearch;
protected SearchBuilder<VlanVO> ZoneVlanSearch;
protected SearchBuilder<VlanVO> NetworkVlanSearch;
protected SearchBuilder<VlanVO> PhysicalNetworkVlanSearch;
protected SearchBuilder<VlanVO> ZoneVlanIdSearch;
protected SearchBuilder<VlanVO> ZoneSearch;
protected SearchBuilder<VlanVO> ZoneTypeSearch;
protected SearchBuilder<VlanVO> ZoneTypeAllPodsSearch;
protected SearchBuilder<VlanVO> ZoneTypePodSearch;
protected SearchBuilder<VlanVO> ZoneVlanSearch;
protected SearchBuilder<VlanVO> NetworkVlanSearch;
protected SearchBuilder<VlanVO> PhysicalNetworkVlanSearch;
@Inject protected PodVlanMapDao _podVlanMapDao;
@Inject protected AccountVlanMapDao _accountVlanMapDao;
@Inject protected IPAddressDao _ipAddressDao;
@Inject protected PodVlanMapDao _podVlanMapDao;
@Inject protected AccountVlanMapDao _accountVlanMapDao;
@Inject protected IPAddressDao _ipAddressDao;
@Override
public VlanVO findByZoneAndVlanId(long zoneId, String vlanId) {
SearchCriteria<VlanVO> sc = ZoneVlanIdSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanId", vlanId);
SearchCriteria<VlanVO> sc = ZoneVlanIdSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanId", vlanId);
return findOneBy(sc);
}
@Override
public List<VlanVO> listByZone(long zoneId) {
SearchCriteria<VlanVO> sc = ZoneSearch.create();
sc.setParameters("zoneId", zoneId);
return listBy(sc);
SearchCriteria<VlanVO> sc = ZoneSearch.create();
sc.setParameters("zoneId", zoneId);
return listBy(sc);
}
public VlanDaoImpl() {
ZoneVlanIdSearch = createSearchBuilder();
ZoneVlanIdSearch.and("zoneId", ZoneVlanIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
ZoneVlanIdSearch = createSearchBuilder();
ZoneVlanIdSearch.and("zoneId", ZoneVlanIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
ZoneVlanIdSearch.and("vlanId", ZoneVlanIdSearch.entity().getVlanTag(), SearchCriteria.Op.EQ);
ZoneVlanIdSearch.done();
@ -105,79 +104,79 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
@Override
public List<VlanVO> listZoneWideVlans(long zoneId, VlanType vlanType, String vlanId){
SearchCriteria<VlanVO> sc = ZoneVlanSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanId", vlanId);
sc.setParameters("vlanType", vlanType);
return listBy(sc);
SearchCriteria<VlanVO> sc = ZoneVlanSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanId", vlanId);
sc.setParameters("vlanType", vlanType);
return listBy(sc);
}
@Override
public List<VlanVO> listByZoneAndType(long zoneId, VlanType vlanType) {
SearchCriteria<VlanVO> sc = ZoneTypeSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanType", vlanType);
@Override
public List<VlanVO> listByZoneAndType(long zoneId, VlanType vlanType) {
SearchCriteria<VlanVO> sc = ZoneTypeSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanType", vlanType);
return listBy(sc);
}
}
@Override
@Override
public List<VlanVO> listByType(VlanType vlanType) {
SearchCriteria<VlanVO> sc = ZoneTypeSearch.create();
sc.setParameters("vlanType", vlanType);
return listBy(sc);
}
@Override
public List<VlanVO> listVlansForPod(long podId) {
//FIXME: use a join statement to improve the performance (should be minor since we expect only one or two
List<PodVlanMapVO> vlanMaps = _podVlanMapDao.listPodVlanMapsByPod(podId);
List<VlanVO> result = new ArrayList<VlanVO>();
for (PodVlanMapVO pvmvo: vlanMaps) {
result.add(findById(pvmvo.getVlanDbId()));
}
return result;
}
@Override
public List<VlanVO> listVlansForPod(long podId) {
//FIXME: use a join statement to improve the performance (should be minor since we expect only one or two
List<PodVlanMapVO> vlanMaps = _podVlanMapDao.listPodVlanMapsByPod(podId);
List<VlanVO> result = new ArrayList<VlanVO>();
for (PodVlanMapVO pvmvo: vlanMaps) {
result.add(findById(pvmvo.getVlanDbId()));
}
return result;
}
@Override
public List<VlanVO> listVlansForPodByType(long podId, VlanType vlanType) {
//FIXME: use a join statement to improve the performance (should be minor since we expect only one or two)
List<PodVlanMapVO> vlanMaps = _podVlanMapDao.listPodVlanMapsByPod(podId);
List<VlanVO> result = new ArrayList<VlanVO>();
for (PodVlanMapVO pvmvo: vlanMaps) {
VlanVO vlan =findById(pvmvo.getVlanDbId());
if (vlan.getVlanType() == vlanType) {
result.add(vlan);
}
}
return result;
}
@Override
public List<VlanVO> listVlansForPodByType(long podId, VlanType vlanType) {
//FIXME: use a join statement to improve the performance (should be minor since we expect only one or two)
List<PodVlanMapVO> vlanMaps = _podVlanMapDao.listPodVlanMapsByPod(podId);
List<VlanVO> result = new ArrayList<VlanVO>();
for (PodVlanMapVO pvmvo: vlanMaps) {
VlanVO vlan =findById(pvmvo.getVlanDbId());
if (vlan.getVlanType() == vlanType) {
result.add(vlan);
}
}
return result;
}
@Override
public List<VlanVO> listVlansForAccountByType(Long zoneId, long accountId, VlanType vlanType) {
//FIXME: use a join statement to improve the performance (should be minor since we expect only one or two)
List<AccountVlanMapVO> vlanMaps = _accountVlanMapDao.listAccountVlanMapsByAccount(accountId);
List<VlanVO> result = new ArrayList<VlanVO>();
for (AccountVlanMapVO acvmvo: vlanMaps) {
VlanVO vlan =findById(acvmvo.getVlanDbId());
if (vlan.getVlanType() == vlanType && (zoneId == null || vlan.getDataCenterId() == zoneId)) {
result.add(vlan);
}
}
return result;
}
@Override
public List<VlanVO> listVlansForAccountByType(Long zoneId, long accountId, VlanType vlanType) {
//FIXME: use a join statement to improve the performance (should be minor since we expect only one or two)
List<AccountVlanMapVO> vlanMaps = _accountVlanMapDao.listAccountVlanMapsByAccount(accountId);
List<VlanVO> result = new ArrayList<VlanVO>();
for (AccountVlanMapVO acvmvo: vlanMaps) {
VlanVO vlan =findById(acvmvo.getVlanDbId());
if (vlan.getVlanType() == vlanType && (zoneId == null || vlan.getDataCenterId() == zoneId)) {
result.add(vlan);
}
}
return result;
}
@Override
public void addToPod(long podId, long vlanDbId) {
PodVlanMapVO pvmvo = new PodVlanMapVO(podId, vlanDbId);
_podVlanMapDao.persist(pvmvo);
@Override
public void addToPod(long podId, long vlanDbId) {
PodVlanMapVO pvmvo = new PodVlanMapVO(podId, vlanDbId);
_podVlanMapDao.persist(pvmvo);
}
}
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
boolean result = super.configure(name, params);
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
boolean result = super.configure(name, params);
ZoneTypeAllPodsSearch = createSearchBuilder();
ZoneTypeAllPodsSearch.and("zoneId", ZoneTypeAllPodsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
ZoneTypeAllPodsSearch.and("vlanType", ZoneTypeAllPodsSearch.entity().getVlanType(), SearchCriteria.Op.EQ);
@ -199,117 +198,117 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
PodVlanSearch2.done();
ZoneTypePodSearch.done();
return result;
}
return result;
}
private VlanVO findNextVlan(long zoneId, Vlan.VlanType vlanType) {
List<VlanVO> allVlans = listByZoneAndType(zoneId, vlanType);
List<VlanVO> emptyVlans = new ArrayList<VlanVO>();
List<VlanVO> fullVlans = new ArrayList<VlanVO>();
private VlanVO findNextVlan(long zoneId, Vlan.VlanType vlanType) {
List<VlanVO> allVlans = listByZoneAndType(zoneId, vlanType);
List<VlanVO> emptyVlans = new ArrayList<VlanVO>();
List<VlanVO> fullVlans = new ArrayList<VlanVO>();
// Try to find a VLAN that is partially allocated
for (VlanVO vlan : allVlans) {
long vlanDbId = vlan.getId();
// Try to find a VLAN that is partially allocated
for (VlanVO vlan : allVlans) {
long vlanDbId = vlan.getId();
int countOfAllocatedIps = _ipAddressDao.countIPs(zoneId, vlanDbId, true);
int countOfAllIps = _ipAddressDao.countIPs(zoneId, vlanDbId, false);
int countOfAllocatedIps = _ipAddressDao.countIPs(zoneId, vlanDbId, true);
int countOfAllIps = _ipAddressDao.countIPs(zoneId, vlanDbId, false);
if ((countOfAllocatedIps > 0) && (countOfAllocatedIps < countOfAllIps)) {
return vlan;
} else if (countOfAllocatedIps == 0) {
emptyVlans.add(vlan);
} else if (countOfAllocatedIps == countOfAllIps) {
fullVlans.add(vlan);
}
}
if ((countOfAllocatedIps > 0) && (countOfAllocatedIps < countOfAllIps)) {
return vlan;
} else if (countOfAllocatedIps == 0) {
emptyVlans.add(vlan);
} else if (countOfAllocatedIps == countOfAllIps) {
fullVlans.add(vlan);
}
}
if (emptyVlans.isEmpty()) {
return null;
}
if (emptyVlans.isEmpty()) {
return null;
}
// Try to find an empty VLAN with the same tag/subnet as a VLAN that is full
for (VlanVO fullVlan : fullVlans) {
for (VlanVO emptyVlan : emptyVlans) {
if (fullVlan.getVlanTag().equals(emptyVlan.getVlanTag()) &&
fullVlan.getVlanGateway().equals(emptyVlan.getVlanGateway()) &&
fullVlan.getVlanNetmask().equals(emptyVlan.getVlanNetmask())) {
return emptyVlan;
}
}
}
// Try to find an empty VLAN with the same tag/subnet as a VLAN that is full
for (VlanVO fullVlan : fullVlans) {
for (VlanVO emptyVlan : emptyVlans) {
if (fullVlan.getVlanTag().equals(emptyVlan.getVlanTag()) &&
fullVlan.getVlanGateway().equals(emptyVlan.getVlanGateway()) &&
fullVlan.getVlanNetmask().equals(emptyVlan.getVlanNetmask())) {
return emptyVlan;
}
}
}
// Return a random empty VLAN
return emptyVlans.get(0);
}
// Return a random empty VLAN
return emptyVlans.get(0);
}
@Override
public boolean zoneHasDirectAttachUntaggedVlans(long zoneId) {
SearchCriteria<VlanVO> sc = ZoneTypeAllPodsSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanType", VlanType.DirectAttached);
@Override
public boolean zoneHasDirectAttachUntaggedVlans(long zoneId) {
SearchCriteria<VlanVO> sc = ZoneTypeAllPodsSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanType", VlanType.DirectAttached);
return listIncludingRemovedBy(sc).size() > 0;
}
}
public Pair<String, VlanVO> assignPodDirectAttachIpAddress(long zoneId,
long podId, long accountId, long domainId) {
SearchCriteria<VlanVO> sc = ZoneTypePodSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanType", VlanType.DirectAttached);
sc.setJoinParameters("vlan", "podId", podId);
public Pair<String, VlanVO> assignPodDirectAttachIpAddress(long zoneId,
long podId, long accountId, long domainId) {
SearchCriteria<VlanVO> sc = ZoneTypePodSearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("vlanType", VlanType.DirectAttached);
sc.setJoinParameters("vlan", "podId", podId);
VlanVO vlan = findOneIncludingRemovedBy(sc);
if (vlan == null) {
return null;
}
VlanVO vlan = findOneIncludingRemovedBy(sc);
if (vlan == null) {
return null;
}
return null;
return null;
// String ipAddress = _ipAddressDao.assignIpAddress(accountId, domainId, vlan.getId(), false).getAddress();
// if (ipAddress == null) {
// return null;
// }
// return new Pair<String, VlanVO>(ipAddress, vlan);
}
}
@Override
@DB
public List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType, String vlanId){
@Override
@DB
public List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType, String vlanId){
StringBuilder sql = new StringBuilder(FindZoneWideVlans);
StringBuilder sql = new StringBuilder(FindZoneWideVlans);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, dcId);
pstmt.setString(2, vlanType);
pstmt.setString(3, vlanId);
Transaction txn = Transaction.currentTxn();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
pstmt.setLong(1, dcId);
pstmt.setString(2, vlanType);
pstmt.setString(3, vlanId);
ResultSet rs = pstmt.executeQuery();
List<VlanVO> zoneWideVlans = new ArrayList<VlanVO>();
ResultSet rs = pstmt.executeQuery();
List<VlanVO> zoneWideVlans = new ArrayList<VlanVO>();
while (rs.next()) {
zoneWideVlans.add(toEntityBean(rs, false));
}
while (rs.next()) {
zoneWideVlans.add(toEntityBean(rs, false));
}
return zoneWideVlans;
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e);
}
}
return zoneWideVlans;
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e);
}
}
@Override
@Override
public List<VlanVO> listVlansByNetworkId(long networkOfferingId) {
SearchCriteria<VlanVO> sc = NetworkVlanSearch.create();
SearchCriteria<VlanVO> sc = NetworkVlanSearch.create();
sc.setParameters("networkOfferingId", networkOfferingId);
return listBy(sc);
}
@Override
public List<VlanVO> listVlansByPhysicalNetworkId(long physicalNetworkId) {
SearchCriteria<VlanVO> sc = PhysicalNetworkVlanSearch.create();
SearchCriteria<VlanVO> sc = PhysicalNetworkVlanSearch.create();
sc.setParameters("physicalNetworkId", physicalNetworkId);
return listBy(sc);
}

View File

@ -18,7 +18,6 @@ package com.cloud.deploy;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -74,7 +73,6 @@ import com.cloud.storage.dao.VolumeDao;
import com.cloud.user.AccountManager;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Adapters;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
@ -115,7 +113,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
@Override
public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vmProfile,
DeploymentPlan plan, ExcludeList avoid)
throws InsufficientServerCapacityException {
throws InsufficientServerCapacityException {
VirtualMachine vm = vmProfile.getVirtualMachine();
DataCenter dc = _dcDao.findById(vm.getDataCenterIdToDeployIn());
@ -313,7 +311,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
}
podsWithCapacity.removeAll(disabledPods);
}
}
}
}else{
if (s_logger.isDebugEnabled()) {
s_logger.debug("No pods found having a host with enough capacity, returning.");
@ -438,10 +436,10 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
}
private Map<Short,Float> getCapacityThresholdMap(){
// Lets build this real time so that the admin wont have to restart MS if he changes these values
Map<Short,Float> disableThresholdMap = new HashMap<Short, Float>();
// Lets build this real time so that the admin wont have to restart MS if he changes these values
Map<Short,Float> disableThresholdMap = new HashMap<Short, Float>();
String cpuDisableThresholdString = _configDao.getValue(Config.CPUCapacityDisableThreshold.key());
String cpuDisableThresholdString = _configDao.getValue(Config.CPUCapacityDisableThreshold.key());
float cpuDisableThreshold = NumbersUtil.parseFloat(cpuDisableThresholdString, 0.85F);
disableThresholdMap.put(Capacity.CAPACITY_TYPE_CPU, cpuDisableThreshold);
@ -449,21 +447,21 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
float memoryDisableThreshold = NumbersUtil.parseFloat(memoryDisableThresholdString, 0.85F);
disableThresholdMap.put(Capacity.CAPACITY_TYPE_MEMORY, memoryDisableThreshold);
return disableThresholdMap;
return disableThresholdMap;
}
private List<Short> getCapacitiesForCheckingThreshold(){
List<Short> capacityList = new ArrayList<Short>();
capacityList.add(Capacity.CAPACITY_TYPE_CPU);
capacityList.add(Capacity.CAPACITY_TYPE_MEMORY);
return capacityList;
List<Short> capacityList = new ArrayList<Short>();
capacityList.add(Capacity.CAPACITY_TYPE_CPU);
capacityList.add(Capacity.CAPACITY_TYPE_MEMORY);
return capacityList;
}
private void removeClustersCrossingThreshold(List<Long> clusterListForVmAllocation, ExcludeList avoid, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan){
Map<Short,Float> capacityThresholdMap = getCapacityThresholdMap();
List<Short> capacityList = getCapacitiesForCheckingThreshold();
List<Long> clustersCrossingThreshold = new ArrayList<Long>();
Map<Short,Float> capacityThresholdMap = getCapacityThresholdMap();
List<Short> capacityList = getCapacitiesForCheckingThreshold();
List<Long> clustersCrossingThreshold = new ArrayList<Long>();
ServiceOffering offering = vmProfile.getServiceOffering();
int cpu_requested = offering.getCpu() * offering.getSpeed();
@ -472,28 +470,28 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
// For each capacity get the cluster list crossing the threshold and remove it from the clusterList that will be used for vm allocation.
for(short capacity : capacityList){
if (clusterListForVmAllocation == null || clusterListForVmAllocation.size() == 0){
return;
}
if (clusterListForVmAllocation == null || clusterListForVmAllocation.size() == 0){
return;
}
if (capacity == Capacity.CAPACITY_TYPE_CPU){
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(Capacity.CAPACITY_TYPE_CPU, plan.getDataCenterId(),
capacityThresholdMap.get(capacity), cpu_requested, ApiDBUtils.getCpuOverprovisioningFactor());
}else{
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(),
capacityThresholdMap.get(capacity), ram_requested, 1.0f);//Mem overprov not supported yet
}
if (capacity == Capacity.CAPACITY_TYPE_CPU){
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(Capacity.CAPACITY_TYPE_CPU, plan.getDataCenterId(),
capacityThresholdMap.get(capacity), cpu_requested, ApiDBUtils.getCpuOverprovisioningFactor());
}else{
clustersCrossingThreshold = _capacityDao.listClustersCrossingThreshold(capacity, plan.getDataCenterId(),
capacityThresholdMap.get(capacity), ram_requested, 1.0f);//Mem overprov not supported yet
}
if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0){
// addToAvoid Set
avoid.addClusterList(clustersCrossingThreshold);
// Remove clusters crossing disabled threshold
clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
if (clustersCrossingThreshold != null && clustersCrossingThreshold.size() != 0){
// addToAvoid Set
avoid.addClusterList(clustersCrossingThreshold);
// Remove clusters crossing disabled threshold
clusterListForVmAllocation.removeAll(clustersCrossingThreshold);
s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" +
" crosses the disable capacity threshold: " + capacityThresholdMap.get(capacity) + " for capacity Type : " + capacity + ", skipping these clusters");
}
s_logger.debug("Cannot allocate cluster list " + clustersCrossingThreshold.toString() + " for vm creation since their allocated percentage" +
" crosses the disable capacity threshold: " + capacityThresholdMap.get(capacity) + " for capacity Type : " + capacity + ", skipping these clusters");
}
}
}
@ -801,8 +799,8 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
// when deploying VM based on ISO, we have a service offering and an additional disk offering, use-local storage flag is actually
// saved in service offering, overrde the flag from service offering when it is a ROOT disk
if(!useLocalStorage && vmProfile.getServiceOffering().getUseLocalStorage()) {
if(toBeCreated.getVolumeType() == Volume.Type.ROOT)
useLocalStorage = true;
if(toBeCreated.getVolumeType() == Volume.Type.ROOT)
useLocalStorage = true;
}
}
diskProfile.setUseLocalStorage(useLocalStorage);

View File

@ -37,7 +37,6 @@ import com.cloud.agent.AgentManager;
import com.cloud.alert.AlertManager;
import com.cloud.cluster.ClusterManagerListener;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.StackMaid;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.ClusterDetailsDao;
@ -192,7 +191,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
if(host.getHypervisorType() == HypervisorType.VMware) {
s_logger.info("Don't restart for VMs on host " + host.getId() + " as the host is VMware host");
return;
return;
}
s_logger.warn("Scheduling restart for VMs on host " + host.getId());
@ -268,28 +267,28 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
@Override
public void scheduleRestart(VMInstanceVO vm, boolean investigate) {
Long hostId = vm.getHostId();
if (hostId == null) {
try {
s_logger.debug("Found a vm that is scheduled to be restarted but has no host id: " + vm);
Long hostId = vm.getHostId();
if (hostId == null) {
try {
s_logger.debug("Found a vm that is scheduled to be restarted but has no host id: " + vm);
_itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
} catch (ResourceUnavailableException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
} catch (OperationTimedoutException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
} catch (ConcurrentOperationException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
}
return;
}
return;
}
if(vm.getHypervisorType() == HypervisorType.VMware) {
s_logger.info("Skip HA for VMware VM " + vm.getInstanceName());
return;
}
if(vm.getHypervisorType() == HypervisorType.VMware) {
s_logger.info("Skip HA for VMware VM " + vm.getInstanceName());
return;
}
if (!investigate) {
if (s_logger.isDebugEnabled()) {
@ -319,13 +318,13 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
_itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
} catch (ResourceUnavailableException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
} catch (OperationTimedoutException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
} catch (ConcurrentOperationException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
}
}
@ -420,7 +419,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
Investigator investigator = null;
for(Investigator it : _investigators) {
investigator = it;
investigator = it;
alive = investigator.isVmAlive(vm, host);
s_logger.info(investigator.getName() + " found " + vm + "to be alive? " + alive);
if (alive != null) {
@ -464,13 +463,13 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
_itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
} catch (ResourceUnavailableException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
} catch (OperationTimedoutException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
} catch (ConcurrentOperationException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
}
work.setStep(Step.Scheduled);
@ -481,13 +480,13 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
_itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
} catch (ResourceUnavailableException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
} catch (OperationTimedoutException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
} catch (ConcurrentOperationException e) {
assert false : "How do we hit this when force is true?";
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
}
}
}
@ -785,8 +784,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
_haDao.cleanup(System.currentTimeMillis() - _timeBetweenFailures);
} catch (Exception e) {
s_logger.warn("Error while cleaning up", e);
} finally {
StackMaid.current().exitCleanup();
}
}
}
@ -832,7 +829,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
nextTime = destroyVM(work);
} else {
assert false : "How did we get here with " + wt.toString();
continue;
continue;
}
if (nextTime == null) {
@ -852,7 +849,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
} catch (final Throwable th) {
s_logger.error("Caught this throwable, ", th);
} finally {
StackMaid.current().exitCleanup();
if (work != null) {
NDC.pop();
}

View File

@ -47,7 +47,6 @@ import com.cloud.info.RunningHostCountInfo;
import com.cloud.org.Managed;
import com.cloud.resource.ResourceState;
import com.cloud.utils.DateUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.Attribute;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;
@ -346,8 +345,8 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
public List<HostVO> findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) {
Transaction txn = Transaction.currentTxn();
txn.start();
SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create();
sc.setParameters("lastPinged", lastPingSecondsAfter);
SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create();
sc.setParameters("lastPinged", lastPingSecondsAfter);
//sc.setParameters("resourceStates", ResourceState.ErrorInMaintenance, ResourceState.Maintenance, ResourceState.PrepareForMaintenance, ResourceState.Disabled);
sc.setJoinParameters("ClusterManagedSearch", "managed", Managed.ManagedState.Managed);
List<HostVO> hosts = lockRows(sc, new Filter(HostVO.class, "clusterId", true, 0L, limit), true);
@ -364,22 +363,22 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
@Override @DB
public List<HostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId) {
Transaction txn = Transaction.currentTxn();
Transaction txn = Transaction.currentTxn();
txn.start();
SearchCriteria<HostVO> sc = UnmanagedApplianceSearch.create();
sc.setParameters("lastPinged", lastPingSecondsAfter);
txn.start();
SearchCriteria<HostVO> sc = UnmanagedApplianceSearch.create();
sc.setParameters("lastPinged", lastPingSecondsAfter);
sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.PxeServer, Type.TrafficMonitor, Type.L2Networking);
List<HostVO> hosts = lockRows(sc, null, true);
List<HostVO> hosts = lockRows(sc, null, true);
for (HostVO host : hosts) {
host.setManagementServerId(managementServerId);
update(host.getId(), host);
}
for (HostVO host : hosts) {
host.setManagementServerId(managementServerId);
update(host.getId(), host);
}
txn.commit();
txn.commit();
return hosts;
return hosts;
}
@Override
@ -653,80 +652,80 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
}
@Override
public boolean updateState(Status oldStatus, Event event, Status newStatus, Host vo, Object data) {
HostVO host = findById(vo.getId());
long oldPingTime = host.getLastPinged();
@Override
public boolean updateState(Status oldStatus, Event event, Status newStatus, Host vo, Object data) {
HostVO host = findById(vo.getId());
long oldPingTime = host.getLastPinged();
SearchBuilder<HostVO> sb = createSearchBuilder();
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("update", sb.entity().getUpdated(), SearchCriteria.Op.EQ);
if (newStatus.checkManagementServer()) {
sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ);
sb.closeParen();
}
sb.done();
SearchBuilder<HostVO> sb = createSearchBuilder();
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("update", sb.entity().getUpdated(), SearchCriteria.Op.EQ);
if (newStatus.checkManagementServer()) {
sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
sb.or("msid", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ);
sb.closeParen();
}
sb.done();
SearchCriteria<HostVO> sc = sb.create();
SearchCriteria<HostVO> sc = sb.create();
sc.setParameters("status", oldStatus);
sc.setParameters("id", host.getId());
sc.setParameters("update", host.getUpdated());
long oldUpdateCount = host.getUpdated();
if (newStatus.checkManagementServer()) {
sc.setParameters("ping", oldPingTime);
sc.setParameters("msid", host.getManagementServerId());
}
sc.setParameters("status", oldStatus);
sc.setParameters("id", host.getId());
sc.setParameters("update", host.getUpdated());
long oldUpdateCount = host.getUpdated();
if (newStatus.checkManagementServer()) {
sc.setParameters("ping", oldPingTime);
sc.setParameters("msid", host.getManagementServerId());
}
long newUpdateCount = host.incrUpdated();
UpdateBuilder ub = getUpdateBuilder(host);
ub.set(host, _statusAttr, newStatus);
if (newStatus.updateManagementServer()) {
if (newStatus.lostConnection()) {
ub.set(host, _msIdAttr, null);
} else {
ub.set(host, _msIdAttr, host.getManagementServerId());
}
if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) {
ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10);
}
}
if (event.equals(Event.ManagementServerDown)) {
ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60)));
}
int result = update(ub, sc, null);
assert result <= 1 : "How can this update " + result + " rows? ";
long newUpdateCount = host.incrUpdated();
UpdateBuilder ub = getUpdateBuilder(host);
ub.set(host, _statusAttr, newStatus);
if (newStatus.updateManagementServer()) {
if (newStatus.lostConnection()) {
ub.set(host, _msIdAttr, null);
} else {
ub.set(host, _msIdAttr, host.getManagementServerId());
}
if (event.equals(Event.Ping) || event.equals(Event.AgentConnected)) {
ub.set(host, _pingTimeAttr, System.currentTimeMillis() >> 10);
}
}
if (event.equals(Event.ManagementServerDown)) {
ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60)));
}
int result = update(ub, sc, null);
assert result <= 1 : "How can this update " + result + " rows? ";
if (status_logger.isDebugEnabled() && result == 0) {
HostVO ho = findById(host.getId());
assert ho != null : "How how how? : " + host.getId();
if (status_logger.isDebugEnabled() && result == 0) {
HostVO ho = findById(host.getId());
assert ho != null : "How how how? : " + host.getId();
StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString());
str.append(". Name=").append(host.getName());
str.append("; New=[status=").append(newStatus.toString()).append(":msid=")
.append(newStatus.lostConnection() ? "null" : host.getManagementServerId()).append(":lastpinged=").append(host.getLastPinged()).append("]");
str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=")
.append(oldPingTime).append("]");
str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=")
.append(vo.getLastPinged()).append(":old update count=").append(oldUpdateCount).append("]");
status_logger.debug(str.toString());
} else {
StringBuilder msg = new StringBuilder("Agent status update: [");
msg.append("id = " + host.getId());
msg.append("; name = " + host.getName());
msg.append("; old status = " + oldStatus);
msg.append("; event = " + event);
msg.append("; new status = " + newStatus);
msg.append("; old update count = " + oldUpdateCount);
msg.append("; new update count = " + newUpdateCount + "]");
status_logger.debug(msg.toString());
}
StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString());
str.append(". Name=").append(host.getName());
str.append("; New=[status=").append(newStatus.toString()).append(":msid=")
.append(newStatus.lostConnection() ? "null" : host.getManagementServerId()).append(":lastpinged=").append(host.getLastPinged()).append("]");
str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=")
.append(oldPingTime).append("]");
str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=")
.append(vo.getLastPinged()).append(":old update count=").append(oldUpdateCount).append("]");
status_logger.debug(str.toString());
} else {
StringBuilder msg = new StringBuilder("Agent status update: [");
msg.append("id = " + host.getId());
msg.append("; name = " + host.getName());
msg.append("; old status = " + oldStatus);
msg.append("; event = " + event);
msg.append("; new status = " + newStatus);
msg.append("; old update count = " + oldUpdateCount);
msg.append("; new update count = " + newUpdateCount + "]");
status_logger.debug(msg.toString());
}
return result > 0;
}
return result > 0;
}
@Override
public boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo) {
@ -751,20 +750,20 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
assert ho != null : "How how how? : " + host.getId();
StringBuilder str = new StringBuilder("Unable to update resource state: [");
str.append("m = " + host.getId());
str.append("; name = " + host.getName());
str.append("; old state = " + oldState);
str.append("; event = " + event);
str.append("; new state = " + newState + "]");
state_logger.debug(str.toString());
str.append("m = " + host.getId());
str.append("; name = " + host.getName());
str.append("; old state = " + oldState);
str.append("; event = " + event);
str.append("; new state = " + newState + "]");
state_logger.debug(str.toString());
} else {
StringBuilder msg = new StringBuilder("Resource state update: [");
msg.append("id = " + host.getId());
msg.append("; name = " + host.getName());
msg.append("; old state = " + oldState);
msg.append("; event = " + event);
msg.append("; new state = " + newState + "]");
state_logger.debug(msg.toString());
StringBuilder msg = new StringBuilder("Resource state update: [");
msg.append("id = " + host.getId());
msg.append("; name = " + host.getName());
msg.append("; old state = " + oldState);
msg.append("; event = " + event);
msg.append("; new state = " + newState + "]");
state_logger.debug(msg.toString());
}
return result > 0;
@ -779,15 +778,15 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
return findOneBy(sc);
}
@Override
public List<HostVO> findHypervisorHostInCluster(long clusterId) {
SearchCriteria<HostVO> sc = TypeClusterStatusSearch.create();
sc.setParameters("type", Host.Type.Routing);
sc.setParameters("cluster", clusterId);
sc.setParameters("status", Status.Up);
sc.setParameters("resourceState", ResourceState.Enabled);
@Override
public List<HostVO> findHypervisorHostInCluster(long clusterId) {
SearchCriteria<HostVO> sc = TypeClusterStatusSearch.create();
sc.setParameters("type", Host.Type.Routing);
sc.setParameters("cluster", clusterId);
sc.setParameters("status", Status.Up);
sc.setParameters("resourceState", ResourceState.Enabled);
return listBy(sc);
}
return listBy(sc);
}
}

View File

@ -33,8 +33,6 @@ import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
@Component
@Local(value = { HypervisorGuruManager.class } )
@ -43,53 +41,55 @@ public class HypervisorGuruManagerImpl implements HypervisorGuruManager {
@Inject HostDao _hostDao;
String _name;
String _name;
@Inject List<HypervisorGuru> _hvGuruList;
@Inject List<HypervisorGuru> _hvGuruList;
Map<HypervisorType, HypervisorGuru> _hvGurus = new HashMap<HypervisorType, HypervisorGuru>();
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
return true;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
return true;
}
@PostConstruct
public void init() {
for(HypervisorGuru guru : _hvGuruList) {
_hvGurus.put(guru.getHypervisorType(), guru);
}
}
@PostConstruct
public void init() {
for(HypervisorGuru guru : _hvGuruList) {
_hvGurus.put(guru.getHypervisorType(), guru);
}
}
@Override
public boolean start() {
return true;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public String getName() {
return _name;
}
@Override
public String getName() {
return _name;
}
public HypervisorGuru getGuru(HypervisorType hypervisorType) {
return _hvGurus.get(hypervisorType);
}
@Override
public HypervisorGuru getGuru(HypervisorType hypervisorType) {
return _hvGurus.get(hypervisorType);
}
@Override
public long getGuruProcessedCommandTargetHost(long hostId, Command cmd) {
HostVO hostVo = _hostDao.findById(hostId);
HypervisorGuru hvGuru = null;
if(hostVo.getType() == Host.Type.Routing) {
hvGuru = _hvGurus.get(hostVo.getHypervisorType());
}
HostVO hostVo = _hostDao.findById(hostId);
HypervisorGuru hvGuru = null;
if(hostVo.getType() == Host.Type.Routing) {
hvGuru = _hvGurus.get(hostVo.getHypervisorType());
}
if(hvGuru != null)
return hvGuru.getCommandHostDelegation(hostId, cmd);
if(hvGuru != null)
return hvGuru.getCommandHostDelegation(hostId, cmd);
return hostId;
return hostId;
}
}

View File

@ -36,15 +36,14 @@ import javax.naming.ConfigurationException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.maint.dao.AgentUpgradeDao;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.ComponentLocator;
/**
*
@ -57,7 +56,7 @@ import com.cloud.utils.component.ComponentLocator;
@Component
@Local(UpgradeManager.class)
public class UpgradeManagerImpl implements UpgradeManager {
private final static Logger s_logger = Logger.getLogger(UpgradeManagerImpl.class);
private final static Logger s_logger = Logger.getLogger(UpgradeManagerImpl.class);
private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager();
String _name;
@ -90,7 +89,7 @@ public class UpgradeManagerImpl implements UpgradeManager {
_upgradeDao.persist(vo);
}
}
*/
*/
return state;
}
@ -132,11 +131,11 @@ public class UpgradeManagerImpl implements UpgradeManager {
s_logger.debug("New Agent zip file is now retrieved");
} catch (final HttpException e) {
return "Unable to retrieve the file from " + url;
return "Unable to retrieve the file from " + url;
} catch (final IOException e) {
return "Unable to retrieve the file from " + url;
return "Unable to retrieve the file from " + url;
} finally {
method.releaseConnection();
method.releaseConnection();
}
file.delete();

View File

@ -19,9 +19,7 @@ package com.cloud.migration;
import java.io.File;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import javax.inject.Inject;
@ -32,21 +30,17 @@ import com.cloud.configuration.Resource.ResourceType;
import com.cloud.configuration.ResourceCountVO;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.configuration.dao.ResourceCountDao;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.resource.ResourceManager;
import com.cloud.user.Account;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
@ -57,16 +51,16 @@ import com.cloud.vm.dao.InstanceGroupVMMapDao;
public class Db21to22MigrationUtil {
@Inject private ClusterDao _clusterDao;
@Inject private HostDao _hostDao;
@Inject private AccountDao _accountDao;
@Inject private DomainDao _domainDao;
@Inject private ResourceCountDao _resourceCountDao;
@Inject private InstanceGroupDao _vmGroupDao;
@Inject private InstanceGroupVMMapDao _groupVMMapDao;
@Inject private ConfigurationDao _configurationDao;
@Inject private DataCenterDao _zoneDao;
@Inject private ResourceManager _resourceMgr;
@Inject private ClusterDao _clusterDao;
@Inject private HostDao _hostDao;
@Inject private AccountDao _accountDao;
@Inject private DomainDao _domainDao;
@Inject private ResourceCountDao _resourceCountDao;
@Inject private InstanceGroupDao _vmGroupDao;
@Inject private InstanceGroupVMMapDao _groupVMMapDao;
@Inject private ConfigurationDao _configurationDao;
@Inject private DataCenterDao _zoneDao;
@Inject private ResourceManager _resourceMgr;
private void doMigration() {
setupComponents();
@ -85,8 +79,8 @@ public class Db21to22MigrationUtil {
/* add guid in cluster table */
private void setupClusterGuid() {
//FIXME moving out XenServer code out of server. This upgrade step need to be taken care of
/*
//FIXME moving out XenServer code out of server. This upgrade step need to be taken care of
/*
XenServerConnectionPool _connPool = XenServerConnectionPool.getInstance();
List<ClusterVO> clusters = _clusterDao.listByHyTypeWithoutGuid(HypervisorType.XenServer.toString());
for (ClusterVO cluster : clusters) {
@ -120,7 +114,7 @@ public class Db21to22MigrationUtil {
break;
}
}
*/
*/
}
@ -129,23 +123,23 @@ public class Db21to22MigrationUtil {
* based on the param direct.attach.untagged.vlan.enabled, we update zone to basic or advanced for 2.2
*/
private void migrateZones(){
try {
System.out.println("Migrating zones");
String val = _configurationDao.getValue("direct.attach.untagged.vlan.enabled");
NetworkType networkType;
if(val == null || val.equalsIgnoreCase("true")){
networkType = NetworkType.Basic;
}else{
networkType = NetworkType.Advanced;
}
List<DataCenterVO> existingZones = _zoneDao.listAll();
for(DataCenterVO zone : existingZones){
zone.setNetworkType(networkType);
_zoneDao.update(zone.getId(), zone);
}
} catch (Exception e) {
System.out.println("Unhandled exception in migrateZones()" + e);
}
try {
System.out.println("Migrating zones");
String val = _configurationDao.getValue("direct.attach.untagged.vlan.enabled");
NetworkType networkType;
if(val == null || val.equalsIgnoreCase("true")){
networkType = NetworkType.Basic;
}else{
networkType = NetworkType.Advanced;
}
List<DataCenterVO> existingZones = _zoneDao.listAll();
for(DataCenterVO zone : existingZones){
zone.setNetworkType(networkType);
_zoneDao.update(zone.getId(), zone);
}
} catch (Exception e) {
System.out.println("Unhandled exception in migrateZones()" + e);
}
}
private void migrateResourceCounts() {
@ -177,44 +171,44 @@ public class Db21to22MigrationUtil {
}
private void setupInstanceGroups() {
System.out.println("setting up vm instance groups");
System.out.println("setting up vm instance groups");
//Search for all the vms that have not null groups
Long vmId = 0L;
Long accountId = 0L;
String groupName;
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
txn.start();
try {
String request = "SELECT vm.id, uservm.account_id, vm.group from vm_instance vm, user_vm uservm where vm.group is not null and vm.removed is null and vm.id=uservm.id order by id";
System.out.println(request);
PreparedStatement statement = txn.prepareStatement(request);
ResultSet result = statement.executeQuery();
while (result.next()) {
vmId = result.getLong(1);
accountId = result.getLong(2);
groupName = result.getString(3);
InstanceGroupVO group = _vmGroupDao.findByAccountAndName(accountId, groupName);
//Create vm group if the group doesn't exist for this account
if (group == null) {
group = new InstanceGroupVO(groupName, accountId);
group = _vmGroupDao.persist(group);
System.out.println("Created new isntance group with name " + groupName + " for account id=" + accountId);
}
//Search for all the vms that have not null groups
Long vmId = 0L;
Long accountId = 0L;
String groupName;
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
txn.start();
try {
String request = "SELECT vm.id, uservm.account_id, vm.group from vm_instance vm, user_vm uservm where vm.group is not null and vm.removed is null and vm.id=uservm.id order by id";
System.out.println(request);
PreparedStatement statement = txn.prepareStatement(request);
ResultSet result = statement.executeQuery();
while (result.next()) {
vmId = result.getLong(1);
accountId = result.getLong(2);
groupName = result.getString(3);
InstanceGroupVO group = _vmGroupDao.findByAccountAndName(accountId, groupName);
//Create vm group if the group doesn't exist for this account
if (group == null) {
group = new InstanceGroupVO(groupName, accountId);
group = _vmGroupDao.persist(group);
System.out.println("Created new isntance group with name " + groupName + " for account id=" + accountId);
}
if (group != null) {
InstanceGroupVMMapVO groupVmMapVO = new InstanceGroupVMMapVO(group.getId(), vmId);
_groupVMMapDao.persist(groupVmMapVO);
System.out.println("Assigned vm id=" + vmId + " to group with name " + groupName + " for account id=" + accountId);
}
}
txn.commit();
statement.close();
} catch (Exception e) {
System.out.println("Unhandled exception: " + e);
} finally {
txn.close();
}
if (group != null) {
InstanceGroupVMMapVO groupVmMapVO = new InstanceGroupVMMapVO(group.getId(), vmId);
_groupVMMapDao.persist(groupVmMapVO);
System.out.println("Assigned vm id=" + vmId + " to group with name " + groupName + " for account id=" + accountId);
}
}
txn.commit();
statement.close();
} catch (Exception e) {
System.out.println("Unhandled exception: " + e);
} finally {
txn.close();
}
}

View File

@ -19,7 +19,6 @@ package com.cloud.network;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
@ -33,136 +32,135 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
@Component
@Local(value=IpAddrAllocator.class)
public class ExteralIpAddressAllocator implements IpAddrAllocator{
private static final Logger s_logger = Logger.getLogger(ExteralIpAddressAllocator.class);
String _name;
private static final Logger s_logger = Logger.getLogger(ExteralIpAddressAllocator.class);
String _name;
@Inject ConfigurationDao _configDao = null;
@Inject IPAddressDao _ipAddressDao = null;
@Inject VlanDao _vlanDao;
private boolean _isExternalIpAllocatorEnabled = false;
private String _externalIpAllocatorUrl = null;
private boolean _isExternalIpAllocatorEnabled = false;
private String _externalIpAllocatorUrl = null;
@Override
public IpAddr getPrivateIpAddress(String macAddr, long dcId, long podId) {
if (_externalIpAllocatorUrl == null || this._externalIpAllocatorUrl.equalsIgnoreCase("")) {
return new IpAddr();
}
String urlString = this._externalIpAllocatorUrl + "?command=getIpAddr&mac=" + macAddr + "&dc=" + dcId + "&pod=" + podId;
s_logger.debug("getIP:" + urlString);
@Override
public IpAddr getPrivateIpAddress(String macAddr, long dcId, long podId) {
if (_externalIpAllocatorUrl == null || this._externalIpAllocatorUrl.equalsIgnoreCase("")) {
return new IpAddr();
}
String urlString = this._externalIpAllocatorUrl + "?command=getIpAddr&mac=" + macAddr + "&dc=" + dcId + "&pod=" + podId;
s_logger.debug("getIP:" + urlString);
BufferedReader in = null;
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
conn.setReadTimeout(30000);
BufferedReader in = null;
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
conn.setReadTimeout(30000);
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
s_logger.debug(inputLine);
String[] tokens = inputLine.split(",");
if (tokens.length != 3) {
s_logger.debug("the return value should be: mac,netmask,gateway");
return new IpAddr();
}
return new IpAddr(tokens[0], tokens[1], tokens[2]);
}
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
s_logger.debug(inputLine);
String[] tokens = inputLine.split(",");
if (tokens.length != 3) {
s_logger.debug("the return value should be: mac,netmask,gateway");
return new IpAddr();
}
return new IpAddr(tokens[0], tokens[1], tokens[2]);
}
return new IpAddr();
} catch (MalformedURLException e) {
throw new CloudRuntimeException("URL is malformed " + urlString, e);
} catch (IOException e) {
return new IpAddr();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
return new IpAddr();
} catch (MalformedURLException e) {
throw new CloudRuntimeException("URL is malformed " + urlString, e);
} catch (IOException e) {
return new IpAddr();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
}
@Override
public IpAddr getPublicIpAddress(String macAddr, long dcId, long podId) {
/*TODO: call API to get ip address from external DHCP server*/
return getPrivateIpAddress(macAddr, dcId, podId);
}
@Override
public IpAddr getPublicIpAddress(String macAddr, long dcId, long podId) {
/*TODO: call API to get ip address from external DHCP server*/
return getPrivateIpAddress(macAddr, dcId, podId);
}
@Override
public boolean releasePrivateIpAddress(String ip, long dcId, long podId) {
/*TODO: call API to release the ip address from external DHCP server*/
if (_externalIpAllocatorUrl == null || this._externalIpAllocatorUrl.equalsIgnoreCase("")) {
return false;
}
@Override
public boolean releasePrivateIpAddress(String ip, long dcId, long podId) {
/*TODO: call API to release the ip address from external DHCP server*/
if (_externalIpAllocatorUrl == null || this._externalIpAllocatorUrl.equalsIgnoreCase("")) {
return false;
}
String urlString = this._externalIpAllocatorUrl + "?command=releaseIpAddr&ip=" + ip + "&dc=" + dcId + "&pod=" + podId;
String urlString = this._externalIpAllocatorUrl + "?command=releaseIpAddr&ip=" + ip + "&dc=" + dcId + "&pod=" + podId;
s_logger.debug("releaseIP:" + urlString);
BufferedReader in = null;
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
conn.setReadTimeout(30000);
s_logger.debug("releaseIP:" + urlString);
BufferedReader in = null;
try {
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
conn.setReadTimeout(30000);
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
return true;
} catch (MalformedURLException e) {
throw new CloudRuntimeException("URL is malformed " + urlString, e);
} catch (IOException e) {
return false;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
return true;
} catch (MalformedURLException e) {
throw new CloudRuntimeException("URL is malformed " + urlString, e);
} catch (IOException e) {
return false;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
@Override
public boolean releasePublicIpAddress(String ip, long dcId, long podId) {
/*TODO: call API to release the ip address from external DHCP server*/
return releasePrivateIpAddress(ip, dcId, podId);
}
@Override
public boolean releasePublicIpAddress(String ip, long dcId, long podId) {
/*TODO: call API to release the ip address from external DHCP server*/
return releasePrivateIpAddress(ip, dcId, podId);
}
public boolean exteralIpAddressAllocatorEnabled() {
return _isExternalIpAllocatorEnabled;
}
@Override
public boolean exteralIpAddressAllocatorEnabled() {
return _isExternalIpAllocatorEnabled;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_isExternalIpAllocatorEnabled = Boolean.parseBoolean(_configDao.getValue("direct.attach.network.externalIpAllocator.enabled"));
_externalIpAllocatorUrl = _configDao.getValue("direct.attach.network.externalIpAllocator.url");
_name = name;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_isExternalIpAllocatorEnabled = Boolean.parseBoolean(_configDao.getValue("direct.attach.network.externalIpAllocator.enabled"));
_externalIpAllocatorUrl = _configDao.getValue("direct.attach.network.externalIpAllocator.url");
_name = name;
return true;
}
return true;
}
@Override
public String getName() {
return _name;
}
@Override
public String getName() {
return _name;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public boolean stop() {
return true;
}
}

View File

@ -27,22 +27,21 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.admin.network.AddNetworkDeviceCmd;
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkDeviceCmd;
import org.apache.cloudstack.api.command.admin.network.ListNetworkDeviceCmd;
import org.apache.cloudstack.api.response.NetworkDeviceResponse;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.api.ApiDBUtils;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.IdentityService;
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkDeviceCmd;
import com.cloud.baremetal.ExternalDhcpManager;
import com.cloud.baremetal.PxeServerManager;
import com.cloud.baremetal.PxeServerProfile;
import com.cloud.baremetal.PxeServerManager.PxeServerType;
import com.cloud.baremetal.PxeServerProfile;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenter;
import com.cloud.dc.Pod;
@ -64,14 +63,11 @@ import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.VpnUserDao;
import com.cloud.network.rules.dao.PortForwardingRulesDao;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.server.ManagementServer;
import org.apache.cloudstack.api.response.NetworkDeviceResponse;
import com.cloud.server.api.response.NwDeviceDhcpResponse;
import com.cloud.server.api.response.PxePingResponse;
import com.cloud.user.AccountManager;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserStatisticsDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
@ -149,8 +145,8 @@ public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceMa
if (cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.ExternalDhcp.getName())) {
//Long zoneId = _identityService.getIdentityId("data_center", (String) params.get(ApiConstants.ZONE_ID));
//Long podId = _identityService.getIdentityId("host_pod_ref", (String)params.get(ApiConstants.POD_ID));
Long zoneId = Long.valueOf((String) params.get(ApiConstants.ZONE_ID));
Long podId = Long.valueOf((String)params.get(ApiConstants.POD_ID));
Long zoneId = Long.valueOf((String) params.get(ApiConstants.ZONE_ID));
Long podId = Long.valueOf((String)params.get(ApiConstants.POD_ID));
String type = (String) params.get(ApiConstants.DHCP_SERVER_TYPE);
String url = (String) params.get(ApiConstants.URL);
String username = (String) params.get(ApiConstants.USERNAME);
@ -234,9 +230,9 @@ public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceMa
// } else {
// List<HostVO> devs = _hostDao.listBy(type, zoneId);
// res.addAll(devs);
// }
// }
// return res;
// return res;
return null;
}
@ -281,7 +277,7 @@ public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceMa
@Override
public boolean deleteNetworkDevice(DeleteNetworkDeviceCmd cmd) {
HostVO device = _hostDao.findById(cmd.getId());
return true;
HostVO device = _hostDao.findById(cmd.getId());
return true;
}
}

View File

@ -23,27 +23,31 @@ import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.command.admin.autoscale.CreateCounterCmd;
import org.apache.cloudstack.api.command.user.autoscale.*;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiDispatcher;
import org.apache.cloudstack.api.BaseListAccountResourcesCmd;
import org.apache.cloudstack.api.command.admin.autoscale.CreateCounterCmd;
import org.apache.cloudstack.api.command.user.autoscale.CreateAutoScalePolicyCmd;
import org.apache.cloudstack.api.command.user.autoscale.CreateAutoScaleVmGroupCmd;
import org.apache.cloudstack.api.command.user.autoscale.CreateAutoScaleVmProfileCmd;
import org.apache.cloudstack.api.command.user.autoscale.CreateConditionCmd;
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
import org.apache.cloudstack.api.command.user.autoscale.ListAutoScalePoliciesCmd;
import org.apache.cloudstack.api.command.user.autoscale.ListAutoScaleVmGroupsCmd;
import org.apache.cloudstack.api.command.user.autoscale.ListAutoScaleVmProfilesCmd;
import org.apache.cloudstack.api.command.user.autoscale.ListConditionsCmd;
import org.apache.cloudstack.api.command.user.autoscale.ListCountersCmd;
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScalePolicyCmd;
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScaleVmGroupCmd;
import org.apache.cloudstack.api.command.user.autoscale.UpdateAutoScaleVmProfileCmd;
import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiDispatcher;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
@ -81,7 +85,6 @@ import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.Inject;
import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;

View File

@ -32,7 +32,6 @@ import com.cloud.network.rules.FirewallRule.TrafficType;
import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
@ -291,6 +290,7 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
return listBy(sc);
}
@Override
@DB
public boolean remove(Long id) {
Transaction txn = Transaction.currentTxn();

View File

@ -35,7 +35,6 @@ import com.cloud.network.IPAddressVO;
import com.cloud.network.IpAddress.State;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
@ -111,7 +110,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
virtaulNetworkVlan.and("vlanType", virtaulNetworkVlan.entity().getVlanType(), SearchCriteria.Op.EQ);
AllIpCountForDashboard.join("vlan", virtaulNetworkVlan, virtaulNetworkVlan.entity().getId(),
AllIpCountForDashboard.entity().getVlanId(), JoinBuilder.JoinType.INNER);
AllIpCountForDashboard.entity().getVlanId(), JoinBuilder.JoinType.INNER);
virtaulNetworkVlan.done();
AllIpCountForDashboard.done();
@ -248,7 +247,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
SearchCriteria<Integer> sc = AllIpCountForDashboard.create();
sc.setParameters("dc", dcId);
if (onlyCountAllocated){
sc.setParameters("state", State.Free);
sc.setParameters("state", State.Free);
}
sc.setJoinParameters("vlan", "vlanType", vlanType.toString());
return customSearch(sc, null).get(0);
@ -297,7 +296,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
@Override
public long countAllocatedIPsForAccount(long accountId) {
SearchCriteria<Long> sc = AllocatedIpCountForAccount.create();
SearchCriteria<Long> sc = AllocatedIpCountForAccount.create();
sc.setParameters("account", accountId);
return customSearch(sc, null).get(0);
}
@ -311,9 +310,9 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
@Override
public long countFreePublicIPs() {
SearchCriteria<Long> sc = CountFreePublicIps.create();
sc.setParameters("state", State.Free);
sc.setJoinParameters("vlans", "vlanType", VlanType.VirtualNetwork);
SearchCriteria<Long> sc = CountFreePublicIps.create();
sc.setParameters("state", State.Free);
sc.setJoinParameters("vlans", "vlanType", VlanType.VirtualNetwork);
return customSearch(sc, null).get(0);
}
@ -329,6 +328,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
return listBy(sc);
}
@Override
public long countFreeIPsInNetwork(long networkId) {
SearchCriteria<Long> sc = CountFreePublicIps.create();
sc.setParameters("state", State.Free);

View File

@ -29,7 +29,6 @@ import org.springframework.stereotype.Component;
import com.cloud.network.LoadBalancerVO;
import com.cloud.network.rules.FirewallRule.State;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;

View File

@ -45,7 +45,6 @@ import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDaoImpl;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;

View File

@ -25,14 +25,11 @@ import org.springframework.stereotype.Component;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkVO;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Func;
import com.cloud.utils.db.SearchCriteria.Op;
@Component

View File

@ -25,10 +25,8 @@ import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.network.IPAddressVO;
import com.cloud.network.Site2SiteVpnConnectionVO;
import com.cloud.network.Site2SiteVpnGatewayVO;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.JoinBuilder.JoinType;
import com.cloud.utils.db.SearchBuilder;

View File

@ -23,7 +23,6 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.network.Site2SiteVpnGatewayVO;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;

View File

@ -46,7 +46,7 @@ import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.Nic;

View File

@ -206,7 +206,7 @@ import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.PasswordGenerator;
import com.cloud.utils.StringUtils;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;

View File

@ -27,7 +27,7 @@ import com.cloud.network.dao.FirewallRulesCidrsDaoImpl;
import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.FirewallRule.State;
import com.cloud.network.rules.PortForwardingRuleVO;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;

View File

@ -87,7 +87,7 @@ import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;

View File

@ -26,7 +26,7 @@ import org.springframework.stereotype.Component;
import com.cloud.network.security.SecurityGroupVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;

View File

@ -99,7 +99,7 @@ import com.cloud.user.UserContext;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;

View File

@ -27,7 +27,7 @@ import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.StaticRouteVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;

View File

@ -27,7 +27,7 @@ import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;

View File

@ -70,7 +70,7 @@ import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.PasswordGenerator;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;

View File

@ -70,7 +70,7 @@ import com.cloud.user.dao.AccountDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;

View File

@ -28,7 +28,7 @@ import com.cloud.projects.Project;
import com.cloud.projects.ProjectVO;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;

View File

@ -34,7 +34,7 @@ import com.cloud.dc.dao.ClusterDao;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.network.NetworkManager;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.net.UrlUtil;
public abstract class DiscovererBase implements Discoverer {

View File

@ -46,7 +46,7 @@ import com.cloud.user.User;
import com.cloud.uservm.UserVm;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.Transaction;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;

View File

@ -37,7 +37,7 @@ import com.cloud.user.User;
import com.cloud.user.UserVO;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.SerialVersionUID;
import com.cloud.utils.component.ComponentLocator;
public class RegisterCompleteServlet extends HttpServlet implements ServletContextListener {
public static final Logger s_logger = Logger.getLogger(RegisterCompleteServlet.class.getName());

View File

@ -173,7 +173,7 @@ import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.UriUtils;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Manager;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;

View File

@ -25,7 +25,7 @@ import com.cloud.cluster.CheckPointManager;
import com.cloud.cluster.CleanupMaid;
import com.cloud.server.ManagementServer;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.fsm.NoTransitionException;
import com.cloud.utils.fsm.StateMachine2;

Some files were not shown because too many files have changed in this diff Show More