use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class Upgrade224to225 method addMissingKeys.
private void addMissingKeys(Connection conn) {
PreparedStatement pstmt = null;
try {
s_logger.debug("Adding missing foreign keys");
HashMap<String, String> keyToTableMap = new HashMap<String, String>();
keyToTableMap.put("fk_console_proxy__id", "console_proxy");
keyToTableMap.put("fk_secondary_storage_vm__id", "secondary_storage_vm");
keyToTableMap.put("fk_template_spool_ref__template_id", "template_spool_ref");
keyToTableMap.put("fk_template_spool_ref__pool_id", "template_spool_ref");
keyToTableMap.put("fk_user_vm_details__vm_id", "user_vm_details");
keyToTableMap.put("fk_op_ha_work__instance_id", "op_ha_work");
keyToTableMap.put("fk_op_ha_work__mgmt_server_id", "op_ha_work");
keyToTableMap.put("fk_op_ha_work__host_id", "op_ha_work");
HashMap<String, String> keyToStatementMap = new HashMap<String, String>();
keyToStatementMap.put("fk_console_proxy__id", "(`id`) REFERENCES `vm_instance` (`id`) ON DELETE CASCADE");
keyToStatementMap.put("fk_secondary_storage_vm__id", "(`id`) REFERENCES `vm_instance` (`id`) ON DELETE CASCADE");
keyToStatementMap.put("fk_template_spool_ref__template_id", "(`template_id`) REFERENCES `vm_template` (`id`)");
keyToStatementMap.put("fk_template_spool_ref__pool_id", "(`pool_id`) REFERENCES `storage_pool` (`id`) ON DELETE CASCADE");
keyToStatementMap.put("fk_user_vm_details__vm_id", "(`vm_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE");
keyToStatementMap.put("fk_op_ha_work__instance_id", "(`instance_id`) REFERENCES `vm_instance` (`id`) ON DELETE CASCADE");
keyToStatementMap.put("fk_op_ha_work__mgmt_server_id", "(`mgmt_server_id`) REFERENCES `mshost`(`msid`)");
keyToStatementMap.put("fk_op_ha_work__host_id", "(`host_id`) REFERENCES `host` (`id`)");
for (String key : keyToTableMap.keySet()) {
String tableName = keyToTableMap.get(key);
pstmt = conn.prepareStatement("SELECT * FROM information_schema.table_constraints a JOIN information_schema.key_column_usage b ON a.table_schema = b.table_schema AND a.constraint_name = b.constraint_name WHERE a.table_schema=database() AND a.constraint_type='FOREIGN KEY' and a.constraint_name=?");
pstmt.setString(1, key);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
continue;
}
pstmt = conn.prepareStatement("ALTER TABLE " + tableName + " ADD CONSTRAINT " + key + " FOREIGN KEY " + keyToStatementMap.get(key));
pstmt.executeUpdate();
s_logger.debug("Added missing key " + key + " to table " + tableName);
rs.close();
}
s_logger.debug("Missing keys were added successfully as a part of 224 to 225 upgrade");
pstmt.close();
} catch (SQLException e) {
s_logger.error("Unable to add missing foreign key; following statement was executed:" + pstmt);
throw new CloudRuntimeException("Unable to add missign keys due to exception", e);
}
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class BaremetalPxeElement method prepare.
@Override
@DB
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
if (vm.getType() != Type.User || vm.getHypervisorType() != HypervisorType.BareMetal) {
return false;
}
VMInstanceVO vo = _vmDao.findById(vm.getId());
assert vo != null : "Where ths nic " + nic.getId() + " going???";
if (vo.getLastHostId() == null) {
nic.setMacAddress(dest.getHost().getPrivateMacAddress());
NicVO nicVo = _nicDao.findById(nic.getId());
nicVo.setMacAddress(nic.getMacAddress());
_nicDao.update(nicVo.getId(), nicVo);
/*This vm is just being created */
if (!_pxeMgr.prepare(vm, nic, network, dest, context)) {
throw new CloudRuntimeException("Cannot prepare pxe server");
}
}
if (dest.getDataCenter().getNetworkType() == DataCenter.NetworkType.Advanced) {
prepareVlan(network, dest);
}
return true;
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class Force10BaremetalSwitchBackend method removePortFromVlan.
@Override
public void removePortFromVlan(BaremetalVlanStruct struct) {
String link = buildLink(struct.getSwitchIp(), String.format("/api/running/ftos/interface/vlan/%s", struct.getVlan()));
HttpHeaders headers = createBasicAuthenticationHeader(struct);
HttpEntity<String> request = new HttpEntity<>(headers);
logger.debug(String.format("http get: %s, body: %s", link, request));
ResponseEntity rsp = rest.exchange(link, HttpMethod.GET, request, String.class);
if (rsp.getStatusCode() == HttpStatus.NOT_FOUND) {
logger.debug(String.format("vlan[%s] has been deleted on force10[ip:%s], no need to remove the port[%s] anymore", struct.getVlan(), struct.getSwitchIp(), struct.getPort()));
} else if (rsp.getStatusCode() == HttpStatus.OK) {
PortInfo port = new PortInfo(struct);
XmlObject xml = XmlObjectParser.parseFromString((String) rsp.getBody());
List<XmlObject> ports = xml.getAsList("untagged.tengigabitethernet");
ports.addAll(xml.<XmlObject>getAsList("untagged.gigabitethernet"));
ports.addAll(xml.<XmlObject>getAsList("untagged.fortyGigE"));
List<XmlObject> newPorts = new ArrayList<>();
boolean needRemove = false;
for (XmlObject pxml : ports) {
XmlObject name = pxml.get("name");
if (port.port.equals(name.getText())) {
needRemove = true;
continue;
}
newPorts.add(pxml);
}
if (!needRemove) {
return;
}
xml.setText(null);
xml.removeElement("mtu");
XmlObject tagged = xml.get("untagged");
tagged.removeAllChildren();
for (XmlObject p : newPorts) {
tagged.putElement(p.getTag(), p);
}
request = new HttpEntity<>(xml.dump(), headers);
logger.debug(String.format("http get: %s, body: %s", link, request));
rsp = rest.exchange(link, HttpMethod.PUT, request, String.class);
if (!successHttpStatusCode.contains(rsp.getStatusCode())) {
throw new CloudRuntimeException(String.format("failed to program vlan[%s] for port[%s] on force10[ip:%s]. http status:%s, body dump:%s", struct.getVlan(), struct.getPort(), struct.getSwitchIp(), rsp.getStatusCode(), rsp.getBody()));
} else {
logger.debug(String.format("removed port[%s] from vlan[%s] on force10[ip:%s]", struct.getPort(), struct.getVlan(), struct.getSwitchIp()));
}
} else {
throw new CloudRuntimeException(String.format("force10[ip:%s] returns unexpected error[%s] when http getting %s, body dump:%s", struct.getSwitchIp(), rsp.getStatusCode(), link, rsp.getBody()));
}
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class BaremetalDhcpManagerImpl method addVirtualMachineIntoNetwork.
@Override
public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
Long zoneId = profile.getVirtualMachine().getDataCenterId();
Long podId = profile.getVirtualMachine().getPodIdToDeployIn();
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.BaremetalDhcp, null, podId, zoneId);
if (hosts.size() == 0) {
throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId + " pod " + podId);
}
if (hosts.size() > 1) {
throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId + " pod " + podId);
}
HostVO h = hosts.get(0);
String dns = nic.getIPv4Dns1();
if (dns == null) {
dns = nic.getIPv4Dns2();
}
DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIPv4Address(), profile.getVirtualMachine().getHostName(), null, dns, nic.getIPv4Gateway(), null, _ntwkModel.getExecuteInSeqNtwkElmtCmd());
String errMsg = String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName());
// prepareBareMetalDhcpEntry(nic, dhcpCommand);
try {
Answer ans = _agentMgr.send(h.getId(), dhcpCommand);
if (ans.getResult()) {
s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()));
return true;
} else {
s_logger.debug(errMsg + " " + ans.getDetails());
throw new ResourceUnavailableException(errMsg, DataCenter.class, zoneId);
}
} catch (Exception e) {
s_logger.debug(errMsg, e);
throw new ResourceUnavailableException(errMsg + e.getMessage(), DataCenter.class, zoneId);
}
}
use of com.cloud.utils.exception.CloudRuntimeException in project cloudstack by apache.
the class BaremetalManagerImpl method notifyProvisionDone.
@Override
public void notifyProvisionDone(BaremetalProvisionDoneNotificationCmd cmd) {
QueryBuilder<HostVO> hq = QueryBuilder.create(HostVO.class);
hq.and(hq.entity().getPrivateMacAddress(), SearchCriteria.Op.EQ, cmd.getMac());
HostVO host = hq.find();
if (host == null) {
throw new CloudRuntimeException(String.format("cannot find host[mac:%s]", cmd.getMac()));
}
_hostDao.loadDetails(host);
String vmName = host.getDetail("vmName");
if (vmName == null) {
throw new CloudRuntimeException(String.format("cannot find any baremetal instance running on host[mac:%s]", cmd.getMac()));
}
QueryBuilder<VMInstanceVO> vmq = QueryBuilder.create(VMInstanceVO.class);
vmq.and(vmq.entity().getInstanceName(), SearchCriteria.Op.EQ, vmName);
VMInstanceVO vm = vmq.find();
if (vm == null) {
throw new CloudRuntimeException(String.format("cannot find baremetal instance[name:%s]", vmName));
}
if (State.Starting != vm.getState()) {
throw new CloudRuntimeException(String.format("baremetal instance[name:%s, state:%s] is not in state of Starting", vmName, vm.getState()));
}
vm.setState(State.Running);
vm.setLastHostId(vm.getHostId());
vmDao.update(vm.getId(), vm);
s_logger.debug(String.format("received baremetal provision done notification for vm[id:%s name:%s] running on host[mac:%s, ip:%s]", vm.getId(), vm.getInstanceName(), host.getPrivateMacAddress(), host.getPrivateIpAddress()));
}
Aggregations