@Test public void testPerform() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); final Service service = Mockito.mock(Service.class); final ServiceComponent serviceComponent = Mockito.mock(ServiceComponent.class); Mockito.when(cluster.getService("HDFS")).thenReturn(service); Mockito.when(service.getServiceComponent("SECONDARY_NAMENODE")).thenReturn(serviceComponent); Mockito.when(serviceComponent.getServiceComponentHosts()).thenReturn(Collections.<String, ServiceComponentHost>singletonMap("host", null)); PrerequisiteCheck check = new PrerequisiteCheck(null, null); secondaryNamenodeDeletedCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); Assert.assertEquals("HDFS", check.getFailedOn().toArray(new String[1])[0]); Assert.assertEquals("The SNameNode component must be deleted from host: host.", check.getFailReason()); Mockito.when(serviceComponent.getServiceComponentHosts()).thenReturn(Collections.<String, ServiceComponentHost> emptyMap()); check = new PrerequisiteCheck(null, null); secondaryNamenodeDeletedCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); }
@Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { Set<String> hosts = new HashSet<String>(); final String SECONDARY_NAMENODE = "SECONDARY_NAMENODE"; final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); try { ServiceComponent serviceComponent = cluster.getService(HDFS_SERVICE_NAME).getServiceComponent(SECONDARY_NAMENODE); if (serviceComponent != null) { hosts = serviceComponent.getServiceComponentHosts().keySet(); } } catch (ServiceComponentNotFoundException err) { ; } if (hosts.isEmpty()) { List<HostComponentStateEntity> allHostComponents = hostComponentStateDao.findAll(); for(HostComponentStateEntity hc : allHostComponents) { if (hc.getServiceName().equalsIgnoreCase(HDFS_SERVICE_NAME) && hc.getComponentName().equalsIgnoreCase(SECONDARY_NAMENODE)) { hosts.add(hc.getHostName()); } } } if (!hosts.isEmpty()) { String foundHost = hosts.toArray(new String[hosts.size()])[0]; prerequisiteCheck.getFailedOn().add(HDFS_SERVICE_NAME); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, foundHost)); } }
SecondaryNamenodeDeletedCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { Set<String> hosts = new HashSet<String>(); final String SECONDARY_NAMENODE = "SECONDARY_NAMENODE"; final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); try { ServiceComponent serviceComponent = cluster.getService(HDFS_SERVICE_NAME).getServiceComponent(SECONDARY_NAMENODE); if (serviceComponent != null) { hosts = serviceComponent.getServiceComponentHosts().keySet(); } } catch (ServiceComponentNotFoundException err) { ; } if (hosts.isEmpty()) { List<HostComponentStateEntity> allHostComponents = hostComponentStateDao.findAll(); for(HostComponentStateEntity hc : allHostComponents) { if (hc.getServiceName().equalsIgnoreCase(HDFS_SERVICE_NAME) && hc.getComponentName().equalsIgnoreCase(SECONDARY_NAMENODE)) { hosts.add(hc.getHostName()); } } } if (!hosts.isEmpty()) { String foundHost = hosts.toArray(new String[hosts.size()])[0]; prerequisiteCheck.getFailedOn().add(HDFS_SERVICE_NAME); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, foundHost)); } } }
SecondaryNamenodeDeletedCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { Set<String> hosts = new HashSet<String>(); final String SECONDARY_NAMENODE = "SECONDARY_NAMENODE"; final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); try { ServiceComponent serviceComponent = cluster.getService(HDFS_SERVICE_NAME).getServiceComponent(SECONDARY_NAMENODE); if (serviceComponent != null) { hosts = serviceComponent.getServiceComponentHosts().keySet(); } } catch (ServiceComponentNotFoundException err) { ; } if (hosts.isEmpty()) { List<HostComponentStateEntity> allHostComponents = hostComponentStateDao.findAll(); for(HostComponentStateEntity hc : allHostComponents) { if (hc.getServiceName().equalsIgnoreCase(HDFS_SERVICE_NAME) && hc.getComponentName().equalsIgnoreCase(SECONDARY_NAMENODE)) { hosts.add(hc.getHostName()); } } } if (!hosts.isEmpty()) { String foundHost = hosts.toArray(new String[hosts.size()])[0]; prerequisiteCheck.getFailedOn().add(HDFS_SERVICE_NAME); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, foundHost)); } } SecondaryNamenodeDeletedCheck(); }
SecondaryNamenodeDeletedCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { Set<String> hosts = new HashSet<String>(); final String SECONDARY_NAMENODE = "SECONDARY_NAMENODE"; final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); try { ServiceComponent serviceComponent = cluster.getService(HDFS_SERVICE_NAME).getServiceComponent(SECONDARY_NAMENODE); if (serviceComponent != null) { hosts = serviceComponent.getServiceComponentHosts().keySet(); } } catch (ServiceComponentNotFoundException err) { ; } if (hosts.isEmpty()) { List<HostComponentStateEntity> allHostComponents = hostComponentStateDao.findAll(); for(HostComponentStateEntity hc : allHostComponents) { if (hc.getServiceName().equalsIgnoreCase(HDFS_SERVICE_NAME) && hc.getComponentName().equalsIgnoreCase(SECONDARY_NAMENODE)) { hosts.add(hc.getHostName()); } } } if (!hosts.isEmpty()) { String foundHost = hosts.toArray(new String[hosts.size()])[0]; prerequisiteCheck.getFailedOn().add(HDFS_SERVICE_NAME); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, foundHost)); } } SecondaryNamenodeDeletedCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request); }
SecondaryNamenodeDeletedCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { Set<String> hosts = new HashSet<String>(); final String SECONDARY_NAMENODE = "SECONDARY_NAMENODE"; final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); try { ServiceComponent serviceComponent = cluster.getService(HDFS_SERVICE_NAME).getServiceComponent(SECONDARY_NAMENODE); if (serviceComponent != null) { hosts = serviceComponent.getServiceComponentHosts().keySet(); } } catch (ServiceComponentNotFoundException err) { ; } if (hosts.isEmpty()) { List<HostComponentStateEntity> allHostComponents = hostComponentStateDao.findAll(); for(HostComponentStateEntity hc : allHostComponents) { if (hc.getServiceName().equalsIgnoreCase(HDFS_SERVICE_NAME) && hc.getComponentName().equalsIgnoreCase(SECONDARY_NAMENODE)) { hosts.add(hc.getHostName()); } } } if (!hosts.isEmpty()) { String foundHost = hosts.toArray(new String[hosts.size()])[0]; prerequisiteCheck.getFailedOn().add(HDFS_SERVICE_NAME); prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); String failReason = getFailReason(prerequisiteCheck, request); prerequisiteCheck.setFailReason(String.format(failReason, foundHost)); } } SecondaryNamenodeDeletedCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }