use of javax.naming.ConfigurationException in project cosmic by MissionCriticalCloud.
the class LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper method execute.
@Override
public Answer execute(final CreatePrivateTemplateFromSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplName = libvirtUtilitiesHelper.generateUuidName();
final String tmplFileName = tmplName + ".qcow2";
KvmStoragePool secondaryPool = null;
KvmStoragePool snapshotPool = null;
final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
try {
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
snapshotPool = storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
secondaryPool = storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl());
final KvmPhysicalDisk snapshot = snapshotPool.getPhysicalDisk(command.getSnapshotName());
final String templatePath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
final StorageLayer storage = libvirtComputingResource.getStorage();
storage.mkdirs(templatePath);
final String tmplPath = templateInstallFolder + File.separator + tmplFileName;
final String createTmplPath = libvirtComputingResource.createTmplPath();
final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout();
final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, s_logger);
scriptCommand.add("-t", templatePath);
scriptCommand.add("-n", tmplFileName);
scriptCommand.add("-f", snapshot.getPath());
scriptCommand.execute();
final Processor qcow2Processor = libvirtUtilitiesHelper.buildQcow2Processor(storage);
final FormatInfo info = qcow2Processor.process(templatePath, null, tmplName);
final TemplateLocation loc = libvirtUtilitiesHelper.buildTemplateLocation(storage, templatePath);
loc.create(1, true, tmplName);
loc.addFormat(info);
loc.save();
return new CreatePrivateTemplateAnswer(command, true, "", tmplPath, info.virtualSize, info.size, tmplName, info.format);
} catch (final ConfigurationException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} catch (final InternalErrorException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} catch (final IOException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} catch (final CloudRuntimeException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} finally {
if (secondaryPool != null) {
storagePoolMgr.deleteStoragePool(secondaryPool.getType(), secondaryPool.getUuid());
}
if (snapshotPool != null) {
storagePoolMgr.deleteStoragePool(snapshotPool.getType(), snapshotPool.getUuid());
}
}
}
use of javax.naming.ConfigurationException in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method configure.
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_name = name;
try {
_dcId = Long.parseLong((String) params.get("zone"));
} catch (final NumberFormatException e) {
throw new ConfigurationException("Unable to get the zone " + params.get("zone"));
}
_host.setUuid((String) params.get("guid"));
_name = _host.getUuid();
_host.setIp((String) params.get("ipaddress"));
_username = (String) params.get("username");
_password.add((String) params.get("password"));
_pod = (String) params.get("pod");
_cluster = (String) params.get("cluster");
_privateNetworkName = (String) params.get("private.network.device");
_publicNetworkName = (String) params.get("public.network.device");
_guestNetworkName = (String) params.get("guest.network.device");
_instance = (String) params.get("instance.name");
_linkLocalPrivateNetworkName = (String) params.get("private.linkLocal.device");
if (_linkLocalPrivateNetworkName == null) {
_linkLocalPrivateNetworkName = "cloud_link_local_network";
}
_storageNetworkName1 = (String) params.get("storage.network.device1");
_storageNetworkName2 = (String) params.get("storage.network.device2");
_heartbeatTimeout = NumbersUtil.parseInt((String) params.get("xenserver.heartbeat.timeout"), 120);
_heartbeatInterval = NumbersUtil.parseInt((String) params.get("xenserver.heartbeat.interval"), 60);
String value = (String) params.get("wait");
_wait = NumbersUtil.parseInt(value, 600);
value = (String) params.get("migratewait");
_migratewait = NumbersUtil.parseInt(value, 3600);
_maxNics = NumbersUtil.parseInt((String) params.get("xenserver.nics.max"), 7);
if (_pod == null) {
throw new ConfigurationException("Unable to get the pod");
}
if (_host.getIp() == null) {
throw new ConfigurationException("Unable to get the host address");
}
if (_username == null) {
throw new ConfigurationException("Unable to get the username");
}
if (_password.peek() == null) {
throw new ConfigurationException("Unable to get the password");
}
if (_host.getUuid() == null) {
throw new ConfigurationException("Unable to get the uuid");
}
CheckXenHostInfo();
storageHandler = buildStorageHandler();
_vrResource = new VirtualRoutingResource(this);
if (!_vrResource.configure(params)) {
throw new ConfigurationException("Unable to configure VirtualRoutingResource");
}
return true;
}
use of javax.naming.ConfigurationException in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method CheckXenHostInfo.
private void CheckXenHostInfo() throws ConfigurationException {
final Connection conn = ConnPool.getConnect(_host.getIp(), _username, _password);
if (conn == null) {
throw new ConfigurationException("Can not create connection to " + _host.getIp());
}
try {
Host.Record hostRec = null;
try {
final Host host = Host.getByUuid(conn, _host.getUuid());
hostRec = host.getRecord(conn);
final Pool.Record poolRec = Pool.getAllRecords(conn).values().iterator().next();
_host.setPool(poolRec.uuid);
} catch (final Exception e) {
throw new ConfigurationException("Can not get host information from " + _host.getIp());
}
if (!hostRec.address.equals(_host.getIp())) {
final String msg = "Host " + _host.getIp() + " seems be reinstalled, please remove this host and readd";
s_logger.error(msg);
throw new ConfigurationException(msg);
}
} finally {
try {
Session.logout(conn);
} catch (final Exception e) {
}
}
}
use of javax.naming.ConfigurationException in project cosmic by MissionCriticalCloud.
the class XcpServerDiscoverer method find.
@Override
public Map<? extends ServerResource, Map<String, String>> find(final long dcId, final Long podId, final Long clusterId, final URI url, final String username, final String password, final List<String> hostTags) throws DiscoveryException {
final Map<CitrixResourceBase, Map<String, String>> resources = new HashMap<>();
Connection conn = null;
if (!url.getScheme().equals("http")) {
final String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
s_logger.debug(msg);
return null;
}
if (clusterId == null) {
final String msg = "must specify cluster Id when add host";
s_logger.debug(msg);
throw new RuntimeException(msg);
}
if (podId == null) {
final String msg = "must specify pod Id when add host";
s_logger.debug(msg);
throw new RuntimeException(msg);
}
final ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null || cluster.getHypervisorType() != HypervisorType.XenServer) {
if (s_logger.isInfoEnabled()) {
s_logger.info("invalid cluster id or cluster is not for XenServer hypervisors");
}
return null;
}
try {
final String hostname = url.getHost();
final InetAddress ia = InetAddress.getByName(hostname);
final String hostIp = ia.getHostAddress();
final Queue<String> pass = new LinkedList<>();
pass.add(password);
conn = _connPool.getConnect(hostIp, username, pass);
if (conn == null) {
final String msg = "Unable to get a connection to " + url;
s_logger.debug(msg);
throw new DiscoveryException(msg);
}
final Set<Pool> pools = Pool.getAll(conn);
final Pool pool = pools.iterator().next();
final Pool.Record pr = pool.getRecord(conn);
String poolUuid = pr.uuid;
final Map<Host, Host.Record> hosts = Host.getAllRecords(conn);
String latestHotFix = "";
if (poolHasHotFix(conn, hostIp, XenserverConfigs.XSHotFix62ESP1004)) {
latestHotFix = XenserverConfigs.XSHotFix62ESP1004;
} else if (poolHasHotFix(conn, hostIp, XenserverConfigs.XSHotFix62ESP1)) {
latestHotFix = XenserverConfigs.XSHotFix62ESP1;
}
/*set cluster hypervisor type to xenserver*/
final ClusterVO clu = _clusterDao.findById(clusterId);
if (clu.getGuid() == null) {
setClusterGuid(clu, poolUuid);
} else {
final List<HostVO> clusterHosts = _resourceMgr.listAllHostsInCluster(clusterId);
if (clusterHosts != null && clusterHosts.size() > 0) {
if (!clu.getGuid().equals(poolUuid)) {
final String msg = "Please join the host " + hostIp + " to XS pool " + clu.getGuid() + " through XC/XS before adding it through CS UI";
s_logger.warn(msg);
throw new DiscoveryException(msg);
}
} else {
setClusterGuid(clu, poolUuid);
}
}
// can not use this conn after this point, because this host may join a pool, this conn is retired
if (conn != null) {
try {
Session.logout(conn);
} catch (final Exception e) {
s_logger.debug("Caught exception during logout", e);
}
conn.dispose();
conn = null;
}
poolUuid = clu.getGuid();
_clusterDao.update(clusterId, clu);
if (_checkHvm) {
for (final Map.Entry<Host, Host.Record> entry : hosts.entrySet()) {
final Host.Record record = entry.getValue();
boolean support_hvm = false;
for (final String capability : record.capabilities) {
if (capability.contains("hvm")) {
support_hvm = true;
break;
}
}
if (!support_hvm) {
final String msg = "Unable to add host " + record.address + " because it doesn't support hvm";
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, msg, msg);
s_logger.debug(msg);
throw new RuntimeException(msg);
}
}
}
for (final Map.Entry<Host, Host.Record> entry : hosts.entrySet()) {
final Host.Record record = entry.getValue();
final String hostAddr = record.address;
final String prodVersion = CitrixHelper.getProductVersion(record);
final String xenVersion = record.softwareVersion.get("xen");
String hostOS = record.softwareVersion.get("product_brand");
if (hostOS == null) {
hostOS = record.softwareVersion.get("platform_name");
}
final String hostOSVer = prodVersion;
final String hostKernelVer = record.softwareVersion.get("linux");
if (_resourceMgr.findHostByGuid(record.uuid) != null) {
s_logger.debug("Skipping " + record.address + " because " + record.uuid + " is already in the database.");
continue;
}
final CitrixResourceBase resource = createServerResource(dcId, podId, record, latestHotFix);
s_logger.info("Found host " + record.hostname + " ip=" + record.address + " product version=" + prodVersion);
final Map<String, String> details = new HashMap<>();
final Map<String, Object> params = new HashMap<>();
details.put("url", hostAddr);
details.put("username", username);
params.put("username", username);
details.put("password", password);
params.put("password", password);
params.put("zone", Long.toString(dcId));
params.put("guid", record.uuid);
params.put("pod", podId.toString());
params.put("cluster", clusterId.toString());
params.put("pool", poolUuid);
params.put("ipaddress", record.address);
details.put(HostInfo.HOST_OS, hostOS);
details.put(HostInfo.HOST_OS_VERSION, hostOSVer);
details.put(HostInfo.HOST_OS_KERNEL_VERSION, hostKernelVer);
details.put(HostInfo.HYPERVISOR_VERSION, xenVersion);
final String privateNetworkLabel = _networkMgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.XenServer);
final String storageNetworkLabel = _networkMgr.getDefaultStorageTrafficLabel(dcId, HypervisorType.XenServer);
if (!params.containsKey("private.network.device") && privateNetworkLabel != null) {
params.put("private.network.device", privateNetworkLabel);
details.put("private.network.device", privateNetworkLabel);
}
if (!params.containsKey("storage.network.device1") && storageNetworkLabel != null) {
params.put("storage.network.device1", storageNetworkLabel);
details.put("storage.network.device1", storageNetworkLabel);
}
params.put("router.aggregation.command.each.timeout", _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString()));
params.put("wait", Integer.toString(_wait));
details.put("wait", Integer.toString(_wait));
params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString()));
params.put(Config.XenServerMaxNics.toString().toLowerCase(), _configDao.getValue(Config.XenServerMaxNics.toString()));
params.put(Config.XenServerHeartBeatTimeout.toString().toLowerCase(), _configDao.getValue(Config.XenServerHeartBeatTimeout.toString()));
params.put(Config.XenServerHeartBeatInterval.toString().toLowerCase(), _configDao.getValue(Config.XenServerHeartBeatInterval.toString()));
params.put(Config.InstanceName.toString().toLowerCase(), _instance);
details.put(Config.InstanceName.toString().toLowerCase(), _instance);
try {
resource.configure("XenServer", params);
} catch (final ConfigurationException e) {
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + record.address, "Error is " + e.getMessage());
s_logger.warn("Unable to instantiate " + record.address, e);
continue;
}
resource.start();
resources.put(resource, details);
}
} catch (final SessionAuthenticationFailed e) {
throw new DiscoveredWithErrorException("Authentication error");
} catch (final XenAPIException e) {
s_logger.warn("XenAPI exception", e);
return null;
} catch (final XmlRpcException e) {
s_logger.warn("Xml Rpc Exception", e);
return null;
} catch (final UnknownHostException e) {
s_logger.warn("Unable to resolve the host name", e);
return null;
} catch (final Exception e) {
s_logger.debug("other exceptions: " + e.toString(), e);
return null;
}
return resources;
}
use of javax.naming.ConfigurationException in project cosmic by MissionCriticalCloud.
the class NiciraNvpElement method addNiciraNvpDevice.
@Override
@DB
public NiciraNvpDeviceVO addNiciraNvpDevice(final AddNiciraNvpDeviceCmd cmd) {
final ServerResource resource = new NiciraNvpResource();
final String deviceName = Network.Provider.NiciraNvp.getName();
final NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
if (networkDevice == null) {
throw new CloudRuntimeException("No network device found for " + deviceName);
}
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
final PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
}
final long zoneId = physicalNetwork.getDataCenterId();
final PhysicalNetworkServiceProviderVO ntwkSvcProvider = physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) {
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
} else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
}
if (niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
throw new CloudRuntimeException("A NiciraNvp device is already configured on this physical network");
}
final Map<String, String> params = new HashMap<>();
params.put("guid", UUID.randomUUID().toString());
params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
params.put("name", "Nicira Controller - " + cmd.getHost());
params.put("ip", cmd.getHost());
params.put("adminuser", cmd.getUsername());
params.put("adminpass", cmd.getPassword());
params.put("transportzoneuuid", cmd.getTransportzoneUuid());
// FIXME What to do with multiple isolation types
params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase());
if (cmd.getL3GatewayServiceUuid() != null) {
params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
}
final Map<String, Object> hostdetails = new HashMap<>();
hostdetails.putAll(params);
try {
resource.configure(cmd.getHost(), hostdetails);
final Host host = resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
if (host != null) {
return Transaction.execute(new TransactionCallback<NiciraNvpDeviceVO>() {
@Override
public NiciraNvpDeviceVO doInTransaction(final TransactionStatus status) {
final NiciraNvpDeviceVO niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
niciraNvpDao.persist(niciraNvpDevice);
final DetailVO detail = new DetailVO(host.getId(), "niciranvpdeviceid", String.valueOf(niciraNvpDevice.getId()));
hostDetailsDao.persist(detail);
return niciraNvpDevice;
}
});
} else {
throw new CloudRuntimeException("Failed to add Nicira Nvp Device due to internal error.");
}
} catch (final ConfigurationException e) {
throw new CloudRuntimeException(e.getMessage());
}
}
Aggregations