@Test public void testPerformMixOne() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); Map<String, Service> services = new HashMap<String, Service>(); services.put("ATLAS", Mockito.mock(Service.class)); Mockito.when(cluster.getServices()).thenReturn(services); Map<String, String> checkProperties = new HashMap<String, String>(); checkProperties.put(ServicePresenceCheck.NO_UPGRADE_SUPPORT_SERVICES_PROPERTY_NAME,"MyServiceOne, MyServiceTwo"); checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"Atlas, OldService"); checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"Atlas2, NewService"); PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class); Mockito.when(prerequisiteCheckConfig.getCheckProperties( m_check.getClass().getName())).thenReturn(checkProperties); PrerequisiteCheck check = new PrerequisiteCheck(null, null); PrereqCheckRequest request = new PrereqCheckRequest("cluster"); request.setPrerequisiteCheckConfig(prerequisiteCheckConfig); m_check.perform(check, request); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); }
@Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName()); Set<String> installedServices = cluster.getServices().keySet(); List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request); Map<String, String> removedServices = getRemovedServices(request); List<String> failReasons = new ArrayList<>(); String reason = getFailReason(prerequisiteCheck, request); for(String service: noUpgradeSupportServices){ if (installedServices.contains(service.toUpperCase())){ prerequisiteCheck.getFailedOn().add(service); String msg = String.format(reason, service, service); failReasons.add(msg); } } reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request); for (Map.Entry<String, String> entry : removedServices.entrySet()) { String removedService = entry.getKey(); if(installedServices.contains(removedService.toUpperCase())){ prerequisiteCheck.getFailedOn().add(removedService); String newService = entry.getValue(); String msg = String.format(reason, removedService, newService); failReasons.add(msg); } } if(!failReasons.isEmpty()){ prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n')); } }
ServicePresenceCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName()); Set<String> installedServices = cluster.getServices().keySet(); List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request); Map<String, String> removedServices = getRemovedServices(request); List<String> failReasons = new ArrayList<>(); String reason = getFailReason(prerequisiteCheck, request); for(String service: noUpgradeSupportServices){ if (installedServices.contains(service.toUpperCase())){ prerequisiteCheck.getFailedOn().add(service); String msg = String.format(reason, service, service); failReasons.add(msg); } } reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request); for (Map.Entry<String, String> entry : removedServices.entrySet()) { String removedService = entry.getKey(); if(installedServices.contains(removedService.toUpperCase())){ prerequisiteCheck.getFailedOn().add(removedService); String newService = entry.getValue(); String msg = String.format(reason, removedService, newService); failReasons.add(msg); } } if(!failReasons.isEmpty()){ prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n')); } } }
ServicePresenceCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName()); Set<String> installedServices = cluster.getServices().keySet(); List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request); Map<String, String> removedServices = getRemovedServices(request); List<String> failReasons = new ArrayList<>(); String reason = getFailReason(prerequisiteCheck, request); for(String service: noUpgradeSupportServices){ if (installedServices.contains(service.toUpperCase())){ prerequisiteCheck.getFailedOn().add(service); String msg = String.format(reason, service, service); failReasons.add(msg); } } reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request); for (Map.Entry<String, String> entry : removedServices.entrySet()) { String removedService = entry.getKey(); if(installedServices.contains(removedService.toUpperCase())){ prerequisiteCheck.getFailedOn().add(removedService); String newService = entry.getValue(); String msg = String.format(reason, removedService, newService); failReasons.add(msg); } } if(!failReasons.isEmpty()){ prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n')); } } ServicePresenceCheck(); }
ServicePresenceCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName()); Set<String> installedServices = cluster.getServices().keySet(); List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request); Map<String, String> removedServices = getRemovedServices(request); List<String> failReasons = new ArrayList<>(); String reason = getFailReason(prerequisiteCheck, request); for(String service: noUpgradeSupportServices){ if (installedServices.contains(service.toUpperCase())){ prerequisiteCheck.getFailedOn().add(service); String msg = String.format(reason, service, service); failReasons.add(msg); } } reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request); for (Map.Entry<String, String> entry : removedServices.entrySet()) { String removedService = entry.getKey(); if(installedServices.contains(removedService.toUpperCase())){ prerequisiteCheck.getFailedOn().add(removedService); String newService = entry.getValue(); String msg = String.format(reason, removedService, newService); failReasons.add(msg); } } if(!failReasons.isEmpty()){ prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n')); } } ServicePresenceCheck(); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); }
ServicePresenceCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName()); Set<String> installedServices = cluster.getServices().keySet(); List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request); Map<String, String> removedServices = getRemovedServices(request); List<String> failReasons = new ArrayList<>(); String reason = getFailReason(prerequisiteCheck, request); for(String service: noUpgradeSupportServices){ if (installedServices.contains(service.toUpperCase())){ prerequisiteCheck.getFailedOn().add(service); String msg = String.format(reason, service, service); failReasons.add(msg); } } reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request); for (Map.Entry<String, String> entry : removedServices.entrySet()) { String removedService = entry.getKey(); if(installedServices.contains(removedService.toUpperCase())){ prerequisiteCheck.getFailedOn().add(removedService); String newService = entry.getValue(); String msg = String.format(reason, removedService, newService); failReasons.add(msg); } } if(!failReasons.isEmpty()){ prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n')); } } ServicePresenceCheck(); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }