use of com.cloud.hypervisor.hyperv.resource.HypervDirectConnectResource in project cloudstack by apache.
the class HypervServerDiscoverer method find.
// End Listener implementation
// Returns server component used by server manager to operate the plugin.
// Server component is a ServerResource. If a connected agent is used, the
// ServerResource is
// ignored in favour of another created in response to
@Override
public final Map<? extends ServerResource, Map<String, String>> find(final long dcId, final Long podId, final Long clusterId, final URI uri, final String username, final String password, final List<String> hostTags) throws DiscoveryException {
if (s_logger.isInfoEnabled()) {
s_logger.info("Discover host. dc(zone): " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + uri.getHost());
}
// Assertions
if (podId == null) {
if (s_logger.isInfoEnabled()) {
s_logger.info("No pod is assigned, skipping the discovery in" + " Hyperv discoverer");
}
return null;
}
// ClusterVO exists
ClusterVO cluster = _clusterDao.findById(clusterId);
// database
if (cluster == null) {
if (s_logger.isInfoEnabled()) {
s_logger.info("No cluster in database for cluster id " + clusterId);
}
return null;
}
if (cluster.getHypervisorType() != HypervisorType.Hyperv) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Cluster " + clusterId + "is not for Hyperv hypervisors");
}
return null;
}
if (!uri.getScheme().equals("http")) {
String msg = "urlString is not http so we're not taking care of" + " the discovery for this: " + uri;
s_logger.debug(msg);
return null;
}
try {
String hostname = uri.getHost();
InetAddress ia = InetAddress.getByName(hostname);
String agentIp = ia.getHostAddress();
String uuidSeed = agentIp;
String guidWithTail = calcServerResourceGuid(uuidSeed) + "-HypervResource";
if (_resourceMgr.findHostByGuid(guidWithTail) != null) {
s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database.");
return null;
}
s_logger.info("Creating" + HypervDirectConnectResource.class.getName() + " HypervDummyResourceBase for zone/pod/cluster " + dcId + "/" + podId + "/" + clusterId);
// This GUID may change.
if (cluster.getGuid() == null) {
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes(Charset.forName("UTF-8"))).toString());
_clusterDao.update(clusterId, cluster);
}
// Settings required by all server resources managing a hypervisor
Map<String, Object> params = new HashMap<String, Object>();
params.put("zone", Long.toString(dcId));
params.put("pod", Long.toString(podId));
params.put("cluster", Long.toString(clusterId));
params.put("guid", guidWithTail);
params.put("ipaddress", agentIp);
// Hyper-V specific settings
Map<String, String> details = new HashMap<String, String>();
details.put("url", uri.getHost());
details.put("username", username);
details.put("password", password);
details.put("cluster.guid", cluster.getGuid());
params.putAll(details);
params.put("router.aggregation.command.each.timeout", _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString()));
HypervDirectConnectResource resource = new HypervDirectConnectResource();
resource.configure(agentIp, params);
// Assert
// TODO: test by using bogus URL and bogus virtual path in URL
ReadyCommand ping = new ReadyCommand();
Answer pingAns = resource.executeRequest(ping);
if (pingAns == null || !pingAns.getResult()) {
String errMsg = "Agent not running, or no route to agent on at " + uri;
s_logger.debug(errMsg);
throw new DiscoveryException(errMsg);
}
Map<HypervDirectConnectResource, Map<String, String>> resources = new HashMap<HypervDirectConnectResource, Map<String, String>>();
resources.put(resource, details);
// TODO: does the resource have to create a connection?
return resources;
} catch (ConfigurationException e) {
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + uri.getHost(), "Error is " + e.getMessage());
s_logger.warn("Unable to instantiate " + uri.getHost(), e);
} catch (UnknownHostException e) {
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + uri.getHost(), "Error is " + e.getMessage());
s_logger.warn("Unable to instantiate " + uri.getHost(), e);
} catch (Exception e) {
String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage();
s_logger.warn(msg);
}
return null;
}
Aggregations