|
18 | 18 | */ |
19 | 19 | package org.apache.cloudstack.storage.test; |
20 | 20 |
|
| 21 | +import java.net.URI; |
| 22 | +import java.net.URISyntaxException; |
21 | 23 | import java.util.HashMap; |
22 | 24 | import java.util.Map; |
23 | 25 |
|
|
36 | 38 | import com.cloud.agent.api.StartupCommand; |
37 | 39 | import com.cloud.agent.manager.AgentAttache; |
38 | 40 | import com.cloud.agent.manager.Commands; |
| 41 | +import com.cloud.dc.ClusterDetailsDao; |
| 42 | +import com.cloud.dc.ClusterVO; |
| 43 | +import com.cloud.dc.dao.ClusterDao; |
39 | 44 | import com.cloud.exception.AgentUnavailableException; |
40 | 45 | import com.cloud.exception.ConnectionException; |
| 46 | +import com.cloud.exception.DiscoveryException; |
41 | 47 | import com.cloud.exception.OperationTimedoutException; |
42 | 48 | import com.cloud.host.HostEnvironment; |
43 | 49 | import com.cloud.host.HostVO; |
44 | 50 | import com.cloud.host.Status.Event; |
45 | 51 | import com.cloud.host.dao.HostDao; |
46 | 52 | import com.cloud.hypervisor.Hypervisor.HypervisorType; |
| 53 | +import com.cloud.hypervisor.vmware.VmwareServerDiscoverer; |
47 | 54 | import com.cloud.hypervisor.xen.resource.XcpOssResource; |
48 | 55 | import com.cloud.resource.ServerResource; |
49 | 56 | import com.cloud.utils.component.ManagerBase; |
| 57 | +import com.cloud.utils.exception.CloudRuntimeException; |
50 | 58 |
|
51 | 59 | public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentManager { |
52 | 60 | private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class); |
53 | 61 | private Map<Long, ServerResource> hostResourcesMap = new HashMap<Long, ServerResource>(); |
54 | 62 | @Inject |
55 | 63 | HostDao hostDao; |
| 64 | + @Inject |
| 65 | + ClusterDao clusterDao; |
| 66 | + @Inject |
| 67 | + ClusterDetailsDao clusterDetailsDao; |
56 | 68 | @Override |
57 | 69 | public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { |
58 | 70 | // TODO Auto-generated method stub |
@@ -104,14 +116,39 @@ protected void loadResource(Long hostId) { |
104 | 116 | ServerResource resource = null; |
105 | 117 | if (host.getHypervisorType() == HypervisorType.XenServer) { |
106 | 118 | resource = new XcpOssResource(); |
| 119 | + try { |
| 120 | + resource.configure(host.getName(), params); |
| 121 | + |
| 122 | + } catch (ConfigurationException e) { |
| 123 | + logger.debug("Failed to load resource:" + e.toString()); |
| 124 | + } |
| 125 | + } else if (host.getHypervisorType() == HypervisorType.VMware) { |
| 126 | + ClusterVO cluster = clusterDao.findById(host.getClusterId()); |
| 127 | + String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue(); |
| 128 | + URI uri; |
| 129 | + try { |
| 130 | + uri = new URI(url); |
| 131 | + String userName = clusterDetailsDao.findDetail(cluster.getId(), "username").getValue(); |
| 132 | + String password = clusterDetailsDao.findDetail(cluster.getId(), "password").getValue(); |
| 133 | + VmwareServerDiscoverer discover = new VmwareServerDiscoverer(); |
| 134 | + |
| 135 | + Map<? extends ServerResource, Map<String, String>> resources = discover.find(host.getDataCenterId(), host.getPodId(), host.getClusterId(), uri, userName, password, null); |
| 136 | + for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) { |
| 137 | + resource = entry.getKey(); |
| 138 | + } |
| 139 | + if (resource == null) { |
| 140 | + throw new CloudRuntimeException("can't find resource"); |
| 141 | + } |
| 142 | + } catch (DiscoveryException e) { |
| 143 | + // TODO Auto-generated catch block |
| 144 | + e.printStackTrace(); |
| 145 | + } catch (URISyntaxException e) { |
| 146 | + // TODO Auto-generated catch block |
| 147 | + e.printStackTrace(); |
| 148 | + } |
107 | 149 | } |
108 | 150 |
|
109 | | - try { |
110 | | - resource.configure(host.getName(), params); |
111 | | - hostResourcesMap.put(hostId, resource); |
112 | | - } catch (ConfigurationException e) { |
113 | | - logger.debug("Failed to load resource:" + e.toString()); |
114 | | - } |
| 151 | + hostResourcesMap.put(hostId, resource); |
115 | 152 | HostEnvironment env = new HostEnvironment(); |
116 | 153 | SetupCommand cmd = new SetupCommand(env); |
117 | 154 | cmd.setNeedSetup(true); |
|
0 commit comments