use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class LibvirtServerDiscoverer method deleteHost.
@Override
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
if (host.getType() != Host.Type.Routing || (host.getHypervisorType() != HypervisorType.KVM && host.getHypervisorType() != HypervisorType.LXC)) {
return null;
}
_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
try {
ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null);
_agentMgr.send(host.getId(), cmd);
} catch (AgentUnavailableException e) {
s_logger.warn("Sending ShutdownCommand failed: ", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Sending ShutdownCommand failed: ", e);
}
return new DeleteHostAnswer(true);
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class SecurityGroupManagerImpl method handleVmMigrated.
protected void handleVmMigrated(VMInstanceVO vm) {
if (!isVmSecurityGroupEnabled(vm.getId()))
return;
if (vm.getType() != VirtualMachine.Type.User) {
Commands cmds = null;
NetworkRulesSystemVmCommand nrc = new NetworkRulesSystemVmCommand(vm.getInstanceName(), vm.getType());
cmds = new Commands(nrc);
try {
_agentMgr.send(vm.getHostId(), cmds);
} catch (AgentUnavailableException e) {
s_logger.debug(e.toString());
} catch (OperationTimedoutException e) {
s_logger.debug(e.toString());
}
} else {
List<Long> affectedVms = new ArrayList<Long>();
affectedVms.add(vm.getId());
scheduleRulesetUpdateToHosts(affectedVms, true, null);
}
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class SecurityGroupManagerImpl method securityGroupRulesForVmSecIp.
@Override
public boolean securityGroupRulesForVmSecIp(long nicId, String secondaryIp, boolean ruleAction) {
Account caller = CallContext.current().getCallingAccount();
if (secondaryIp == null) {
throw new InvalidParameterValueException("Vm secondaryIp can't be null");
}
NicVO nic = _nicDao.findById(nicId);
long vmId = nic.getInstanceId();
UserVm vm = _userVMDao.findById(vmId);
if (vm == null || vm.getType() != VirtualMachine.Type.User) {
throw new InvalidParameterValueException("Can't configure the SG ipset, arprules rules for the non existing or non user vm");
}
// Verify permissions
_accountMgr.checkAccess(caller, null, false, vm);
// Validate parameters
List<SecurityGroupVO> vmSgGrps = getSecurityGroupsForVm(vmId);
if (vmSgGrps.isEmpty()) {
s_logger.debug("Vm is not in any Security group ");
return true;
}
//If network does not support SG service, no need add SG rules for secondary ip
Network network = _networkModel.getNetwork(nic.getNetworkId());
if (!_networkModel.isSecurityGroupSupportedInNetwork(network)) {
s_logger.debug("Network " + network + " is not enabled with security group service, " + "so not applying SG rules for secondary ip");
return true;
}
String vmMac = vm.getPrivateMacAddress();
String vmName = vm.getInstanceName();
if (vmMac == null || vmName == null) {
throw new InvalidParameterValueException("vm name or vm mac can't be null");
}
//create command for the to add ip in ipset and arptables rules
NetworkRulesVmSecondaryIpCommand cmd = new NetworkRulesVmSecondaryIpCommand(vmName, vmMac, secondaryIp, ruleAction);
s_logger.debug("Asking agent to configure rules for vm secondary ip");
Commands cmds = null;
cmds = new Commands(cmd);
try {
_agentMgr.send(vm.getHostId(), cmds);
} catch (AgentUnavailableException e) {
s_logger.debug(e.toString());
} catch (OperationTimedoutException e) {
s_logger.debug(e.toString());
}
return true;
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class SecurityGroupManagerImpl2 method sendRulesetUpdates.
public void sendRulesetUpdates(SecurityGroupWork work) {
Long userVmId = work.getInstanceId();
UserVm vm = _userVMDao.findById(userVmId);
if (vm != null && vm.getState() == State.Running) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("SecurityGroupManager v2: found vm, " + userVmId + " state=" + vm.getState());
}
Map<PortAndProto, Set<String>> ingressRules = generateRulesForVM(userVmId, SecurityRuleType.IngressRule);
Map<PortAndProto, Set<String>> egressRules = generateRulesForVM(userVmId, SecurityRuleType.EgressRule);
Long agentId = vm.getHostId();
if (agentId != null) {
String privateIp = vm.getPrivateIpAddress();
NicVO nic = _nicDao.findByIp4AddressAndVmId(privateIp, vm.getId());
List<String> nicSecIps = null;
if (nic != null) {
if (nic.getSecondaryIp()) {
nicSecIps = _nicSecIpDao.getSecondaryIpAddressesForNic(nic.getId());
}
}
SecurityGroupRulesCmd cmd = generateRulesetCmd(vm.getInstanceName(), vm.getPrivateIpAddress(), nic.getIPv6Address(), vm.getPrivateMacAddress(), vm.getId(), null, work.getLogsequenceNumber(), ingressRules, egressRules, nicSecIps);
cmd.setMsId(_serverId);
if (s_logger.isDebugEnabled()) {
s_logger.debug("SecurityGroupManager v2: sending ruleset update for vm " + vm.getInstanceName() + ":ingress num rules=" + cmd.getIngressRuleSet().size() + ":egress num rules=" + cmd.getEgressRuleSet().size() + " num cidrs=" + cmd.getTotalNumCidrs() + " sig=" + cmd.getSignature());
}
Commands cmds = new Commands(cmd);
try {
_agentMgr.send(agentId, cmds, _answerListener);
if (s_logger.isTraceEnabled()) {
s_logger.trace("SecurityGroupManager v2: sent ruleset updates for " + vm.getInstanceName() + " curr queue size=" + _workQueue.size());
}
} catch (AgentUnavailableException e) {
s_logger.debug("Unable to send updates for vm: " + userVmId + "(agentid=" + agentId + ")");
_workTracker.handleException(agentId);
}
}
} else {
if (s_logger.isDebugEnabled()) {
if (vm != null)
s_logger.debug("No rules sent to vm " + vm + "state=" + vm.getState());
else
s_logger.debug("Could not find vm: No rules sent to vm " + userVmId);
}
}
}
use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method sendCommandsToInternalLbVm.
protected boolean sendCommandsToInternalLbVm(final VirtualRouter internalLbVm, final Commands cmds) throws AgentUnavailableException {
Answer[] answers = null;
try {
answers = _agentMgr.send(internalLbVm.getHostId(), cmds);
} catch (final OperationTimedoutException e) {
s_logger.warn("Timed Out", e);
throw new AgentUnavailableException("Unable to send commands to virtual router ", internalLbVm.getHostId(), e);
}
if (answers == null) {
return false;
}
if (answers.length != cmds.size()) {
return false;
}
boolean result = true;
if (answers.length > 0) {
for (final Answer answer : answers) {
if (!answer.getResult()) {
result = false;
break;
}
}
}
return result;
}
Aggregations