UpgradeCatalog200 extends AbstractUpgradeCatalog { protected void removeNagiosService() { executeInTransaction(new RemoveNagiosRunnable()); } @Inject  UpgradeCatalog200(Injector injector); @Override String getTargetVersion(); @Override void executePreDMLUpdates();  }
@Test public void testDeleteNagiosService() throws Exception { UpgradeCatalog200 upgradeCatalog200 = injector.getInstance(UpgradeCatalog200.class); ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class); HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class); HostComponentStateDAO hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class); ClusterServiceDAO clusterServiceDao = injector.getInstance(ClusterServiceDAO.class); StackDAO stackDAO = injector.getInstance(StackDAO.class); injector.getInstance(AmbariMetaInfo.class); StackEntity stackEntity = stackDAO.find(DESIRED_STACK.getStackName(), DESIRED_STACK.getStackVersion()); assertNotNull(stackEntity); final ClusterEntity clusterEntity = upgradeCatalogHelper.createCluster( injector, CLUSTER_NAME, stackEntity); final ClusterServiceEntity clusterServiceEntityNagios = upgradeCatalogHelper.addService( injector, clusterEntity, "NAGIOS", stackEntity); final HostEntity hostEntity = upgradeCatalogHelper.createHost(injector, clusterEntity, HOST_NAME); upgradeCatalogHelper.addComponent(injector, clusterEntity, clusterServiceEntityNagios, hostEntity, "NAGIOS_SERVER", stackEntity); ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName( clusterEntity.getClusterId(), "NAGIOS", "NAGIOS_SERVER"); assertNotNull(serviceComponentDesiredStateEntity); HostComponentDesiredStateEntity hcDesiredStateEntity = hostComponentDesiredStateDAO.findByIndex( clusterEntity.getClusterId(), "NAGIOS", "NAGIOS_SERVER", hostEntity.getHostId() ); assertNotNull(hcDesiredStateEntity); HostComponentStateEntity hcStateEntity = hostComponentStateDAO.findByIndex( clusterEntity.getClusterId(), "NAGIOS", "NAGIOS_SERVER", hostEntity.getHostId()); assertNotNull(hcStateEntity); ClusterServiceEntity clusterService = clusterServiceDao.findByClusterAndServiceNames( CLUSTER_NAME, "NAGIOS"); upgradeCatalog200.removeNagiosService(); clusterService = clusterServiceDao.findByClusterAndServiceNames( CLUSTER_NAME, "NAGIOS"); assertNull(clusterService); }