private boolean CheckUrl(URI url) throws DiscoveryException { if ("http".equals(url.getScheme()) || "https".equals(url.getScheme())) { String msg = "Discovering " + url + ": " + _params; LOGGER.debug(msg); } else { String msg = "urlString is not http(s) so we're not taking care of the discovery for this: " + url; LOGGER.info(msg); throw new DiscoveryException(msg); } return true; }
@Override public void execute() { try { List<? extends Host> result = _resourceService.discoverHosts(this); ListResponse<HostResponse> response = new ListResponse<HostResponse>(); List<HostResponse> hostResponses = new ArrayList<HostResponse>(); if (result != null && result.size() > 0) { for (Host host : result) { HostResponse hostResponse = _responseGenerator.createHostResponse(host); hostResponses.add(hostResponse); } } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add host"); } response.setResponses(hostResponses); response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } }
@Test public void testExecuteForDiscoveryException() { addHostCmd._resourceService = resourceService; try { Mockito.when(resourceService.discoverHosts(addHostCmd)).thenThrow(DiscoveryException.class); } catch (InvalidParameterValueException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (DiscoveryException e) { e.printStackTrace(); } try { addHostCmd.execute(); } catch (ServerApiException exception) { Assert.assertNull(exception.getDescription()); } }
@Test public void testExecuteForNullResult() { ResourceService resourceService = Mockito.mock(ResourceService.class); addHostCmd._resourceService = resourceService; try { Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn(null); } catch (InvalidParameterValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DiscoveryException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { addHostCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add host", exception.getDescription()); } }
String msg = "must specify cluster Id when add host"; LOGGER.info(msg); throw new DiscoveryException(msg); String msg = "must specify pod Id when add host"; LOGGER.info(msg); throw new DiscoveryException(msg); String msg = "invalid cluster id or cluster is not for Ovm3 hypervisors"; LOGGER.info(msg); throw new DiscoveryException(msg); } else { LOGGER.debug("cluster: " + cluster); String msg = "Agent user name must be specified"; LOGGER.info(msg); throw new DiscoveryException(msg); String msg = "Agent password must be specified"; LOGGER.info(msg); throw new DiscoveryException(msg); String msg = "Agent port must be specified"; LOGGER.info(msg); throw new DiscoveryException(msg); String msg = "The host " + hostIp + " has been added before"; LOGGER.info(msg); throw new DiscoveryException(msg);
@Test public void testExecuteForNullResult() { ResourceService resourceService = Mockito.mock(ResourceService.class); try { Mockito.when(resourceService.discoverCluster(addClusterCmd)).thenReturn(null); } catch (ResourceInUseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DiscoveryException e) { // TODO Auto-generated catch block e.printStackTrace(); } addClusterCmd._resourceService = resourceService; try { addClusterCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add cluster", exception.getDescription()); } }
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
String errMsg = "Agent not running, or no route to agent on at " + uri; s_logger.debug(errMsg); throw new DiscoveryException(errMsg);
import java.util.List; import org.openid4java.consumer.ConsumerManager; import org.openid4java.discovery.DiscoveryException; import org.openid4java.discovery.DiscoveryInformation; public class XRDSConsumer { public static void main(String[] args) { ConsumerManager manager = new ConsumerManager(); try { //get XRDS from Google discovery url List<DiscoveryInformation> discoveries = manager.discover("https://www.google.com/accounts/o8/id"); for(DiscoveryInformation info: discoveries) { //will get something like: https://www.google.com/accounts/o8/ud System.out.println(info.getOPEndpoint()); } } catch (DiscoveryException e) { e.printStackTrace(); } } }
@Override public void execute() { Map<String, String> dm = new HashMap<String, String>(); dm.put(ApiConstants.ACCOUNT, getAccount()); dm.put(ApiConstants.USERNAME, getUsername()); dm.put(ApiConstants.KEY, getKey()); try{ ImageStore result = _storageService.discoverImageStore(null, getUrl(), "Swift", null, dm); ImageStoreResponse storeResponse = null; if (result != null) { storeResponse = _responseGenerator.createImageStoreResponse(result); storeResponse.setResponseName(getCommandName()); storeResponse.setObjectName("secondarystorage"); setResponseObject(storeResponse); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Swift secondary storage"); } } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } }
sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp, username, password); if (sshConnection == null) { throw new DiscoveryException(String.format("Cannot connect to ovm host(IP=%1$s, username=%2$s, password=%3$s, discover failed", hostIp, username, password)); throw new DiscoveryException("Can not find /etc/ovs-agent/agent.ini " + hostIp);
} catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ResourceInUseException ex) { s_logger.warn("Exception: ", ex);
String msg = "Unable to get a connection to " + url; s_logger.debug(msg); throw new DiscoveryException(msg); + clu.getGuid() + " through XC/XS before adding it through CS UI"; s_logger.warn(msg); throw new DiscoveryException(msg);
@Override public void execute(){ try{ ImageStore result = _storageService.discoverImageStore(null, getUrl(), "NFS", getZoneId(), null); ImageStoreResponse storeResponse = null; if (result != null ) { storeResponse = _responseGenerator.createImageStoreResponse(result); storeResponse.setResponseName(getCommandName()); storeResponse.setObjectName("secondarystorage"); setResponseObject(storeResponse); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } }
final String msg = "Do not support HypervisorType " + hypervisorType + " for " + url; s_logger.warn(msg); throw new DiscoveryException(msg); throw new DiscoveryException("Unable to add the host");
@Override public void execute(){ try{ ImageStore result = _storageService.migrateToObjectStore(getName(), getUrl(), getProviderName(), getDetails()); ImageStoreResponse storeResponse = null; if (result != null ) { storeResponse = _responseGenerator.createImageStoreResponse(result); storeResponse.setResponseName(getCommandName()); storeResponse.setObjectName("imagestore"); setResponseObject(storeResponse); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } }
throw new DiscoveryException("Unable to add the external cluster"); } finally { if (!success) {
@Override public void execute(){ try{ ImageStore result = _storageService.discoverImageStore(getName(), getUrl(), getProviderName(), getZoneId(), getDetails()); ImageStoreResponse storeResponse = null; if (result != null) { storeResponse = _responseGenerator.createImageStoreResponse(result); storeResponse.setResponseName(getCommandName()); storeResponse.setObjectName("imagestore"); setResponseObject(storeResponse); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { s_logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } }