@Test(expected = CloudConnectorException.class) public void openStackNullFlavor() { try { Group g1 = new Group("name", InstanceGroupType.GATEWAY, new ArrayList<>(), null, null, null, "loginUserName", "publicKey", 50, Optional.empty()); List<Group> instanceGroups = ImmutableList.of(g1); when(flavorService.list()).thenReturn(null); underTest.flavorsExist(osClient, instanceGroups); } catch (Exception e) { Assert.assertEquals("No flavor found on OpenStack", e.getMessage()); throw e; } }
public void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups) { if (instanceGroups == null) { throw new CloudConnectorException("Cannot validate Flavors if InstanceGroup is null"); } List<? extends Flavor> flavors = osClient.compute().flavors().list(); if (flavors == null || flavors.isEmpty()) { throw new CloudConnectorException("No flavor found on OpenStack"); } Set<String> notFoundFlavors = new HashSet<>(); for (Group instanceGroup : instanceGroups) { String instanceType = instanceGroup.getReferenceInstanceTemplate().getFlavor(); boolean found = false; for (Flavor flavor : flavors) { if (flavor.getName().equalsIgnoreCase(instanceType)) { found = true; break; } } if (!found) { notFoundFlavors.add(instanceType); } } if (!notFoundFlavors.isEmpty()) { LOGGER.info("Not found flavors: {}", notFoundFlavors); throw new CloudConnectorException(String.format("Not found flavors: %s", notFoundFlavors)); } }
OpenStackFlavorVerifier { public void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups) { if (instanceGroups == null) { throw new CloudConnectorException("Cannot validate Flavors if InstanceGroup is null"); } List<? extends Flavor> flavors = osClient.compute().flavors().list(); if (flavors == null || flavors.isEmpty()) { throw new CloudConnectorException("No flavor found on OpenStack"); } Set<String> notFoundFlavors = new HashSet<>(); for (Group instanceGroup : instanceGroups) { String instanceType = instanceGroup.getReferenceInstanceTemplate().getFlavor(); boolean found = false; for (Flavor flavor : flavors) { if (flavor.getName().equalsIgnoreCase(instanceType)) { found = true; break; } } if (!found) { notFoundFlavors.add(instanceType); } } if (!notFoundFlavors.isEmpty()) { LOGGER.info("Not found flavors: {}", notFoundFlavors); throw new CloudConnectorException(String.format("Not found flavors: %s", notFoundFlavors)); } } }
OpenStackFlavorVerifier { public void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups) { if (instanceGroups == null) { throw new CloudConnectorException("Cannot validate Flavors if InstanceGroup is null"); } List<? extends Flavor> flavors = osClient.compute().flavors().list(); if (flavors == null || flavors.isEmpty()) { throw new CloudConnectorException("No flavor found on OpenStack"); } Set<String> notFoundFlavors = new HashSet<>(); for (Group instanceGroup : instanceGroups) { String instanceType = instanceGroup.getReferenceInstanceTemplate().getFlavor(); boolean found = false; for (Flavor flavor : flavors) { if (flavor.getName().equalsIgnoreCase(instanceType)) { found = true; break; } } if (!found) { notFoundFlavors.add(instanceType); } } if (!notFoundFlavors.isEmpty()) { LOGGER.info("Not found flavors: {}", notFoundFlavors); throw new CloudConnectorException(String.format("Not found flavors: %s", notFoundFlavors)); } }  }
OpenStackFlavorVerifier { public void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups) { if (instanceGroups == null) { throw new CloudConnectorException("Cannot validate Flavors if InstanceGroup is null"); } List<? extends Flavor> flavors = osClient.compute().flavors().list(); if (flavors == null || flavors.isEmpty()) { throw new CloudConnectorException("No flavor found on OpenStack"); } Set<String> notFoundFlavors = new HashSet<>(); for (Group instanceGroup : instanceGroups) { String instanceType = instanceGroup.getReferenceInstanceTemplate().getFlavor(); boolean found = false; for (Flavor flavor : flavors) { if (flavor.getName().equalsIgnoreCase(instanceType)) { found = true; break; } } if (!found) { notFoundFlavors.add(instanceType); } } if (!notFoundFlavors.isEmpty()) { LOGGER.info("Not found flavors: {}", notFoundFlavors); throw new CloudConnectorException(String.format("Not found flavors: %s", notFoundFlavors)); } }  void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups); }
OpenStackFlavorVerifier { public void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups) { if (instanceGroups == null) { throw new CloudConnectorException("Cannot validate Flavors if InstanceGroup is null"); } List<? extends Flavor> flavors = osClient.compute().flavors().list(); if (flavors == null || flavors.isEmpty()) { throw new CloudConnectorException("No flavor found on OpenStack"); } Set<String> notFoundFlavors = new HashSet<>(); for (Group instanceGroup : instanceGroups) { String instanceType = instanceGroup.getReferenceInstanceTemplate().getFlavor(); boolean found = false; for (Flavor flavor : flavors) { if (flavor.getName().equalsIgnoreCase(instanceType)) { found = true; break; } } if (!found) { notFoundFlavors.add(instanceType); } } if (!notFoundFlavors.isEmpty()) { LOGGER.info("Not found flavors: {}", notFoundFlavors); throw new CloudConnectorException(String.format("Not found flavors: %s", notFoundFlavors)); } }  void flavorsExist(OSClient<?> osClient, Iterable<Group> instanceGroups);  }