use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class DirectAgentTest method testDownloadTemplate.
@Test
public void testDownloadTemplate() {
ImageStoreTO image = Mockito.mock(ImageStoreTO.class);
PrimaryDataStoreTO primaryStore = Mockito.mock(PrimaryDataStoreTO.class);
Mockito.when(primaryStore.getUuid()).thenReturn(getLocalStorageUuid());
// Mockito.when(image.get).thenReturn(primaryStore);
ImageStoreTO imageStore = Mockito.mock(ImageStoreTO.class);
Mockito.when(imageStore.getProtocol()).thenReturn("http");
TemplateObjectTO template = Mockito.mock(TemplateObjectTO.class);
Mockito.when(template.getPath()).thenReturn(getTemplateUrl());
Mockito.when(template.getDataStore()).thenReturn(imageStore);
// Mockito.when(image.getTemplate()).thenReturn(template);
// CopyTemplateToPrimaryStorageCmd cmd = new
// CopyTemplateToPrimaryStorageCmd(image);
Command cmd = null;
try {
agentMgr.send(hostId, cmd);
} catch (AgentUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class Ovm3FenceBuilder method fenceOff.
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.Ovm3) {
LOGGER.debug("Don't know how to fence non Ovm3 hosts " + host.getHypervisorType());
return null;
} else {
LOGGER.debug("Fencing " + vm + " on host " + host + " with params: " + fenceParams);
}
List<HostVO> hosts = resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);
for (HostVO h : hosts) {
if (h.getHypervisorType() == HypervisorType.Ovm3 && h.getStatus() == Status.Up && h.getId() != host.getId()) {
FenceAnswer answer;
try {
answer = (FenceAnswer) agentMgr.send(h.getId(), fence);
} catch (AgentUnavailableException | OperationTimedoutException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Moving on to the next host because " + h.toString() + " is unavailable", e);
}
continue;
}
if (answer != null && answer.getResult()) {
return true;
}
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
}
return false;
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class XenServerFencer method fenceOff.
@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
if (host.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Don't know how to fence non XenServer hosts " + host.getHypervisorType());
return null;
}
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
FenceCommand fence = new FenceCommand(vm, host);
for (HostVO h : hosts) {
if (h.getHypervisorType() == HypervisorType.XenServer) {
if (h.getStatus() != Status.Up) {
continue;
}
if (h.getId() == host.getId()) {
continue;
}
FenceAnswer answer;
try {
Answer ans = _agentMgr.send(h.getId(), fence);
if (!(ans instanceof FenceAnswer)) {
s_logger.debug("Answer is not fenceanswer. Result = " + ans.getResult() + "; Details = " + ans.getDetails());
continue;
}
answer = (FenceAnswer) ans;
} catch (AgentUnavailableException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
continue;
} catch (OperationTimedoutException e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
}
continue;
}
if (answer != null && answer.getResult()) {
return true;
}
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
}
return false;
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class XcpServerDiscoverer method processConnect.
@Override
public void processConnect(com.cloud.host.Host agent, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
if (!(cmd instanceof StartupRoutingCommand)) {
return;
}
long agentId = agent.getId();
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
if (startup.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Not XenServer so moving on.");
return;
}
HostVO host = _hostDao.findById(agentId);
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
if (cluster.getGuid() == null) {
cluster.setGuid(startup.getPool());
_clusterDao.update(cluster.getId(), cluster);
} else if (!cluster.getGuid().equals(startup.getPool())) {
String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
Map<String, String> details = startup.getHostDetails();
String prodBrand = details.get("product_brand").trim();
String prodVersion = details.get("product_version").trim();
String hotfix = details.get(XenserverConfigs.XS620HotFix);
String prodVersionTextShort = details.get("product_version_text_short");
String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
if (!resource.equals(host.getResource())) {
String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource;
s_logger.debug(msg);
host.setResource(resource);
host.setSetup(false);
_hostDao.update(agentId, host);
throw new HypervisorVersionChangedException(msg);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
HostEnvironment env = new HostEnvironment();
SetupCommand setup = new SetupCommand(env);
if (_setupMultipath) {
setup.setMultipathOn();
}
if (!host.isSetup()) {
setup.setNeedSetup(true);
}
try {
Answer answer = _agentMgr.send(agentId, setup);
if (answer != null && answer.getResult() && answer instanceof SetupAnswer) {
host.setSetup(true);
host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
host.setHypervisorVersion(prodVersion);
_hostDao.update(host.getId(), host);
if (((SetupAnswer) answer).needReconnect()) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null"));
}
} catch (AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class InternalLBVMManagerTest method setUp.
@Override
@Before
public void setUp() {
//mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1, 1, 1, 1, false, "alena", Storage.ProvisioningType.THIN, false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
off = setId(off, 1);
List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
list.add(off);
list.add(off);
Mockito.when(_svcOffDao.createSystemServiceOfferings(Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyBoolean(), Matchers.anyString(), Matchers.any(ProvisioningType.class), Matchers.anyBoolean(), Matchers.anyString(), Matchers.anyBoolean(), Matchers.any(VirtualMachine.Type.class), Matchers.anyBoolean())).thenReturn(list);
ComponentContext.initComponentsLifeCycle();
vm = new DomainRouterVO(1L, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, null, false, false, VirtualMachine.Type.InternalLoadBalancerVm, null);
vm.setRole(Role.INTERNAL_LB_VM);
vm = setId(vm, 1);
vm.setPrivateIpAddress("10.2.2.2");
final NicVO nic = new NicVO("somereserver", 1L, 1L, VirtualMachine.Type.InternalLoadBalancerVm);
nic.setIPv4Address(requestedIp);
final List<DomainRouterVO> emptyList = new ArrayList<DomainRouterVO>();
final List<DomainRouterVO> nonEmptyList = new ArrayList<DomainRouterVO>();
nonEmptyList.add(vm);
Mockito.when(_domainRouterDao.listByNetworkAndRole(invalidNtwkId, Role.INTERNAL_LB_VM)).thenReturn(emptyList);
Mockito.when(_domainRouterDao.listByNetworkAndRole(validNtwkId, Role.INTERNAL_LB_VM)).thenReturn(nonEmptyList);
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(validNtwkId, 1)).thenReturn(nic);
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(invalidNtwkId, 1)).thenReturn(nic);
final Answer answer = new Answer(null, true, null);
final Answer[] answers = new Answer[1];
answers[0] = answer;
try {
Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenReturn(answers);
} catch (final AgentUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
createNetwork();
Mockito.when(_ntwkModel.getNetwork(Matchers.anyLong())).thenReturn(ntwk);
Mockito.when(_itMgr.toNicTO(Matchers.any(NicProfile.class), Matchers.any(HypervisorType.class))).thenReturn(null);
Mockito.when(_domainRouterDao.findById(Matchers.anyLong())).thenReturn(vm);
final DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc);
final NetworkOfferingVO networkOfferingVO = new NetworkOfferingVO();
networkOfferingVO.setConcurrentConnections(500);
Mockito.when(_offeringDao.findById(Matchers.anyLong())).thenReturn(networkOfferingVO);
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);
}
Aggregations