Harmony amongst gurus

This commit is contained in:
Alex Huang 2010-11-03 16:33:43 -07:00
parent e27bb550fe
commit a0cb58aad2
9 changed files with 659 additions and 1 deletions

View File

@ -0,0 +1,55 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.vm;
import com.cloud.domain.Domain;
import com.cloud.domain.PartOf;
import com.cloud.user.Account;
import com.cloud.user.OwnedBy;
import com.cloud.user.User;
import com.cloud.utils.Journal;
/**
* Specifies the entity that is calling the api.
*/
public interface ReservationContext extends PartOf, OwnedBy {
/**
* @return the user making the call.
*/
User getCaller();
/**
* @return the account
*/
Account getAccount();
/**
* @return the domain.
*/
Domain getDomain();
/**
* @return the journal
*/
Journal getJournal();
/**
* @return the reservation id.
*/
String getReservationId();
}

View File

@ -0,0 +1,38 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api.check;
import com.cloud.agent.api.Answer;
public class CheckSshAnswer extends Answer {
protected CheckSshAnswer() {
}
public CheckSshAnswer(CheckSshCommand cmd) {
super(cmd, true, null);
}
public CheckSshAnswer(CheckSshCommand cmd, String details) {
super(cmd, false, details);
}
public CheckSshAnswer(CheckSshCommand cmd, Throwable th) {
super(cmd, false, th.getMessage());
}
}

View File

@ -0,0 +1,66 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.agent.api.check;
import com.cloud.agent.api.Command;
public class CheckSshCommand extends Command {
String ip;
int port;
int interval;
int retries;
String name;
protected CheckSshCommand() {
super();
}
public CheckSshCommand(String instanceName, String ip, int port, int interval, int retries) {
super();
this.ip = ip;
this.port = port;
this.interval = interval;
this.retries = retries;
this.name = instanceName;
}
public String getName() {
return name;
}
public String getIp() {
return ip;
}
public int getPort() {
return port;
}
public int getInterval() {
return interval;
}
public int getRetries() {
return retries;
}
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -0,0 +1,24 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.vm;
import com.cloud.utils.db.GenericDao;
public interface ItWorkDao extends GenericDao<ItWorkVO, Long> {
}

View File

@ -0,0 +1,29 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.vm;
import javax.ejb.Local;
import com.cloud.utils.db.GenericDaoBase;
@Local(value=ItWorkDao.class)
public class ItWorkDaoImpl extends GenericDaoBase<ItWorkVO, Long> implements ItWorkDao {
protected ItWorkDaoImpl() {
super();
}
}

View File

@ -0,0 +1,107 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.vm;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="op_it_work")
public class ItWorkVO {
enum Type {
Start;
}
enum State {
Working,
Cancelling,
}
@Id
@Column(name="id")
String id;
@Column(name=GenericDao.CREATED_COLUMN)
Date created;
@Column(name="mgmt_server_id")
long managementServerId;
@Column(name="type")
Type type;
@Column(name="thread")
String threadName;
@Column(name="state")
State state;
@Column(name="cancel_taken")
@Temporal(value=TemporalType.TIMESTAMP)
Date taken;
protected ItWorkVO() {
}
protected ItWorkVO(String id, long managementServerId, Type type) {
this.id = id;
this.managementServerId = managementServerId;
this.type = type;
this.threadName = Thread.currentThread().getName();
}
public String getId() {
return id;
}
public Date getCreated() {
return created;
}
public long getManagementServerId() {
return managementServerId;
}
public Type getType() {
return type;
}
public String getThreadName() {
return threadName;
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
public Date getTaken() {
return taken;
}
}

View File

@ -98,7 +98,7 @@ public class MauriceMoss implements VmManager, ClusterManagerListener {
@Inject private AccountDao _accountDao;
@Inject private DomainDao _domainDao;
@Inject private ClusterManager _clusterMgr;
@Inject private StartWorkDao _workDao;
@Inject private ItWorkDao _workDao;
@Inject(adapter=DeploymentPlanner.class)
private Adapters<DeploymentPlanner> _planners;

View File

@ -0,0 +1,103 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.vm;
import com.cloud.domain.Domain;
import com.cloud.domain.dao.DomainDao;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.Journal;
public class ReservationContextImpl implements ReservationContext {
User _caller;
Account _account;
Domain _domain;
Journal _journal;
String _reservationId;
public ReservationContextImpl(String reservationId, Journal journal, User caller) {
this(reservationId, journal, caller, null, null);
}
public ReservationContextImpl(String reservationId, Journal journal, User caller, Account account) {
this(reservationId, journal, caller, account, null);
}
public ReservationContextImpl(String reservationId, Journal journal, User caller, Account account, Domain domain) {
_caller = caller;
_account = account;
_domain = domain;
_journal = journal;
_reservationId = reservationId;
}
@Override
public long getDomainId() {
return 0;
}
@Override
public long getAccountId() {
return _caller.getAccountId();
}
@Override
public User getCaller() {
return _caller;
}
@Override
public Account getAccount() {
if (_account == null) {
_account = s_accountDao.findByIdIncludingRemoved(_caller.getId());
}
return _account;
}
@Override
public Domain getDomain() {
if (_domain == null) {
getAccount();
_domain = s_domainDao.findByIdIncludingRemoved(_account.getDomainId());
}
return _domain;
}
@Override
public Journal getJournal() {
return _journal;
}
@Override
public String getReservationId() {
return _reservationId;
}
static UserDao s_userDao;
static DomainDao s_domainDao;
static AccountDao s_accountDao;
static public void setComponents(UserDao userDao, DomainDao domainDao, AccountDao accountDao) {
s_userDao = userDao;
s_domainDao = domainDao;
s_accountDao = accountDao;
}
}

View File

@ -0,0 +1,236 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.vm;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.offering.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
import com.cloud.user.Account;
import com.cloud.user.dao.AccountDao;
/**
* Implementation of VirtualMachineProfile.
*
*/
public class VirtualMachineProfileImpl<T extends VMInstanceVO> implements VirtualMachineProfile<T> {
T _vm;
ServiceOfferingVO _offering;
VMTemplateVO _template;
Map<String, Object> _params;
List<NicProfile> _nics = new ArrayList<NicProfile>();
List<VolumeTO> _disks = new ArrayList<VolumeTO>();
StringBuilder _bootArgs = new StringBuilder();
String _guestOs;
Account _owner;
BootloaderType _bootloader;
VirtualMachine.Type _type;
public VirtualMachineProfileImpl(T vm, String guestOs, VMTemplateVO template, ServiceOfferingVO offering, Account owner, Map<String, Object> params) {
_vm = vm;
_template = template;
_offering = offering;
_params = params;
_owner = owner;
if (_params == null) {
_params = new HashMap<String, Object>();
}
_guestOs = guestOs;
_type = vm.getType();
}
public VirtualMachineProfileImpl(VirtualMachine.Type type) {
_type = type;
}
@Override
public String getOs() {
return _guestOs;
}
@Override
public void setBootloader(BootloaderType bootloader) {
_bootloader = bootloader;
}
@Override
public BootloaderType getBootloader() {
return _bootloader;
}
@Override
public String toString() {
return _vm.toString();
}
@Override
public T getVirtualMachine() {
return _vm;
}
@Override
public ServiceOffering getServiceOffering() {
if (_offering == null) {
_offering = s_offeringDao.findByIdIncludingRemoved(_vm.getServiceOfferingId());
}
return _offering;
}
@Override
public void setParameter(String name, Object value) {
_params.put(name, value);
}
@Override
public String getGuestOs() {
return _guestOs;
}
@Override
public VirtualMachineTemplate getTemplate() {
if (_template == null) {
_template = s_templateDao.findByIdIncludingRemoved(_vm.getTemplateId());
}
return _template;
}
@Override
public HypervisorType getHypervisorType() {
getTemplate();
return _template.getHypervisorType();
}
@Override
public long getTemplateId() {
return _vm.getTemplateId();
}
@Override
public long getServiceOfferingId() {
return _vm.getServiceOfferingId();
}
@Override
public long getId() {
return _vm.getId();
}
public void setNics(List<NicProfile> nics) {
_nics = nics;
}
public void setDisks(List<VolumeTO> disks) {
_disks = disks;
}
@Override
public List<NicProfile> getNics() {
return _nics;
}
@Override
public List<VolumeTO> getDisks() {
return _disks;
}
@Override
public void addNic(int index, NicProfile nic) {
_nics.add(index, nic);
}
@Override
public void addDisk(int index, VolumeTO disk) {
_disks.add(index, disk);
}
@Override
public StringBuilder getBootArgsBuilder() {
return _bootArgs;
}
@Override
public void addBootArgs(String... args) {
for (String arg : args) {
_bootArgs.append(arg).append(" ");
}
}
@Override
public VirtualMachine.Type getType() {
return _type;
}
@Override
public Account getOwner() {
if (_owner == null) {
_owner = s_accountDao.findByIdIncludingRemoved(_vm.getAccountId());
}
return _owner;
}
@Override
public String getBootArgs() {
return _bootArgs.toString();
}
static ServiceOfferingDao s_offeringDao;
static VMTemplateDao s_templateDao;
static AccountDao s_accountDao;
static void setComponents(ServiceOfferingDao offeringDao, VMTemplateDao templateDao, AccountDao accountDao) {
s_offeringDao = offeringDao;
s_templateDao = templateDao;
s_accountDao = accountDao;
}
@Override
public void addNic(NicProfile nic) {
_nics.add(nic);
}
@Override
public void addDisk(VolumeTO disk) {
_disks.add(disk);
}
@Override
public Object getParameter(String name) {
return _params.get(name);
}
@Override
public String getHostName() {
return _vm.getHostName();
}
@Override
public String getInstanceName() {
return _vm.getInstanceName();
}
}