@Test public void testDeleteStormRestApiServiceComponent() throws Exception { initData(); ClusterEntity clusterEntity = upgradeCatalogHelper.createCluster(injector, "c1", desiredStackEntity); ClusterServiceEntity clusterServiceEntity = upgradeCatalogHelper.createService( injector, clusterEntity, "STORM"); HostEntity hostEntity = upgradeCatalogHelper.createHost(injector, clusterEntity, "h1"); ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class); ClusterStateDAO clusterStateDAO = injector.getInstance(ClusterStateDAO.class); ClusterStateEntity clusterStateEntity = new ClusterStateEntity(); clusterStateEntity.setClusterId(clusterEntity.getClusterId()); clusterStateEntity.setClusterEntity(clusterEntity); clusterStateEntity.setCurrentStack(desiredStackEntity); clusterStateDAO.create(clusterStateEntity); clusterEntity.setClusterStateEntity(clusterStateEntity); clusterDAO.merge(clusterEntity); ServiceComponentDesiredStateEntity componentDesiredStateEntity = new ServiceComponentDesiredStateEntity(); componentDesiredStateEntity.setClusterId(clusterEntity.getClusterId()); componentDesiredStateEntity.setServiceName(clusterServiceEntity.getServiceName()); componentDesiredStateEntity.setClusterServiceEntity(clusterServiceEntity); componentDesiredStateEntity.setComponentName("STORM_REST_API"); componentDesiredStateEntity.setDesiredStack(desiredStackEntity); ServiceComponentDesiredStateDAO componentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class); componentDesiredStateDAO.create(componentDesiredStateEntity); HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class); HostComponentDesiredStateEntity hostComponentDesiredStateEntity = new HostComponentDesiredStateEntity(); hostComponentDesiredStateEntity.setClusterId(clusterEntity.getClusterId()); hostComponentDesiredStateEntity.setComponentName("STORM_REST_API"); hostComponentDesiredStateEntity.setAdminState(HostComponentAdminState.INSERVICE); hostComponentDesiredStateEntity.setServiceName(clusterServiceEntity.getServiceName()); hostComponentDesiredStateEntity.setServiceComponentDesiredStateEntity(componentDesiredStateEntity); hostComponentDesiredStateEntity.setHostEntity(hostEntity); hostComponentDesiredStateEntity.setDesiredStack(desiredStackEntity); hostComponentDesiredStateDAO.create(hostComponentDesiredStateEntity); HostComponentDesiredStateEntity entity = hostComponentDesiredStateDAO.findAll().get(0); Assert.assertEquals(HostComponentAdminState.INSERVICE.name(), entity.getAdminState().name()); Assert.assertNotNull(componentDesiredStateDAO.findByName(clusterEntity.getClusterId(), "STORM", "STORM_REST_API")); UpgradeCatalog210 upgradeCatalog210 = injector.getInstance(UpgradeCatalog210.class); upgradeCatalog210.removeStormRestApiServiceComponent(); Assert.assertNull(componentDesiredStateDAO.findByName(clusterEntity.getClusterId(), "STORM", "STORM_REST_API")); tearDown(); }
protected void removeStormRestApiServiceComponent() { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); for (final Cluster cluster : clusterMap.values()) { StackId stackId = cluster.getCurrentStackVersion(); if (stackId != null && stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.2") >= 0) { executeInTransaction(new Runnable() { @Override public void run() { ServiceComponentDesiredStateDAO dao = injector.getInstance(ServiceComponentDesiredStateDAO.class); ServiceComponentDesiredStateEntity entity = dao.findByName(cluster.getClusterId(), "STORM", "STORM_REST_API"); if (entity != null) { EntityManager em = getEntityManagerProvider().get(); CriteriaBuilder cb = em.getCriteriaBuilder(); try { LOG.info("Deleting STORM_REST_API service component."); CriteriaDelete<HostComponentStateEntity> hcsDelete = cb.createCriteriaDelete(HostComponentStateEntity.class); CriteriaDelete<HostComponentDesiredStateEntity> hcdDelete = cb.createCriteriaDelete(HostComponentDesiredStateEntity.class); CriteriaDelete<ServiceComponentDesiredStateEntity> scdDelete = cb.createCriteriaDelete(ServiceComponentDesiredStateEntity.class); Root<HostComponentStateEntity> hcsRoot = hcsDelete.from(HostComponentStateEntity.class); Root<HostComponentDesiredStateEntity> hcdRoot = hcdDelete.from(HostComponentDesiredStateEntity.class); Root<ServiceComponentDesiredStateEntity> scdRoot = scdDelete.from(ServiceComponentDesiredStateEntity.class); hcsDelete.where(cb.equal(hcsRoot.get("componentName"), "STORM_REST_API")); hcdDelete.where(cb.equal(hcdRoot.get("componentName"), "STORM_REST_API")); scdDelete.where(cb.equal(scdRoot.get("componentName"), "STORM_REST_API")); em.createQuery(hcsDelete).executeUpdate(); em.createQuery(hcdDelete).executeUpdate(); em.createQuery(scdDelete).executeUpdate(); } catch (Exception e) { LOG.warn("Error deleting STORM_REST_API service component. " + "This could result in issue with ambari server start. " + "Please make sure the STORM_REST_API component is deleted " + "from the database by running following commands:\n" + "delete from hostcomponentdesiredstate where component_name='STORM_REST_API';\n" + "delete from hostcomponentstate where component_name='STORM_REST_API';\n" + "delete from servicecomponentdesiredstate where component_name='STORM_REST_API';\n", e); } } } }); } } } }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void removeStormRestApiServiceComponent() { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); for (final Cluster cluster : clusterMap.values()) { StackId stackId = cluster.getCurrentStackVersion(); if (stackId != null && stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.2") >= 0) { executeInTransaction(new Runnable() { @Override public void run() { ServiceComponentDesiredStateDAO dao = injector.getInstance(ServiceComponentDesiredStateDAO.class); ServiceComponentDesiredStateEntity entity = dao.findByName(cluster.getClusterId(), "STORM", "STORM_REST_API"); if (entity != null) { EntityManager em = getEntityManagerProvider().get(); CriteriaBuilder cb = em.getCriteriaBuilder(); try { LOG.info("Deleting STORM_REST_API service component."); CriteriaDelete<HostComponentStateEntity> hcsDelete = cb.createCriteriaDelete(HostComponentStateEntity.class); CriteriaDelete<HostComponentDesiredStateEntity> hcdDelete = cb.createCriteriaDelete(HostComponentDesiredStateEntity.class); CriteriaDelete<ServiceComponentDesiredStateEntity> scdDelete = cb.createCriteriaDelete(ServiceComponentDesiredStateEntity.class); Root<HostComponentStateEntity> hcsRoot = hcsDelete.from(HostComponentStateEntity.class); Root<HostComponentDesiredStateEntity> hcdRoot = hcdDelete.from(HostComponentDesiredStateEntity.class); Root<ServiceComponentDesiredStateEntity> scdRoot = scdDelete.from(ServiceComponentDesiredStateEntity.class); hcsDelete.where(cb.equal(hcsRoot.get("componentName"), "STORM_REST_API")); hcdDelete.where(cb.equal(hcdRoot.get("componentName"), "STORM_REST_API")); scdDelete.where(cb.equal(scdRoot.get("componentName"), "STORM_REST_API")); em.createQuery(hcsDelete).executeUpdate(); em.createQuery(hcdDelete).executeUpdate(); em.createQuery(scdDelete).executeUpdate(); } catch (Exception e) { LOG.warn("Error deleting STORM_REST_API service component. " + "This could result in issue with ambari server start. " + "Please make sure the STORM_REST_API component is deleted " + "from the database by running following commands:\n" + "delete from hostcomponentdesiredstate where component_name='STORM_REST_API';\n" + "delete from hostcomponentstate where component_name='STORM_REST_API';\n" + "delete from servicecomponentdesiredstate where component_name='STORM_REST_API';\n", e); } } } }); } } } } }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void removeStormRestApiServiceComponent() { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); for (final Cluster cluster : clusterMap.values()) { StackId stackId = cluster.getCurrentStackVersion(); if (stackId != null && stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.2") >= 0) { executeInTransaction(new Runnable() { @Override public void run() { ServiceComponentDesiredStateDAO dao = injector.getInstance(ServiceComponentDesiredStateDAO.class); ServiceComponentDesiredStateEntity entity = dao.findByName(cluster.getClusterId(), "STORM", "STORM_REST_API"); if (entity != null) { EntityManager em = getEntityManagerProvider().get(); CriteriaBuilder cb = em.getCriteriaBuilder(); try { LOG.info("Deleting STORM_REST_API service component."); CriteriaDelete<HostComponentStateEntity> hcsDelete = cb.createCriteriaDelete(HostComponentStateEntity.class); CriteriaDelete<HostComponentDesiredStateEntity> hcdDelete = cb.createCriteriaDelete(HostComponentDesiredStateEntity.class); CriteriaDelete<ServiceComponentDesiredStateEntity> scdDelete = cb.createCriteriaDelete(ServiceComponentDesiredStateEntity.class); Root<HostComponentStateEntity> hcsRoot = hcsDelete.from(HostComponentStateEntity.class); Root<HostComponentDesiredStateEntity> hcdRoot = hcdDelete.from(HostComponentDesiredStateEntity.class); Root<ServiceComponentDesiredStateEntity> scdRoot = scdDelete.from(ServiceComponentDesiredStateEntity.class); hcsDelete.where(cb.equal(hcsRoot.get("componentName"), "STORM_REST_API")); hcdDelete.where(cb.equal(hcdRoot.get("componentName"), "STORM_REST_API")); scdDelete.where(cb.equal(scdRoot.get("componentName"), "STORM_REST_API")); em.createQuery(hcsDelete).executeUpdate(); em.createQuery(hcdDelete).executeUpdate(); em.createQuery(scdDelete).executeUpdate(); } catch (Exception e) { LOG.warn("Error deleting STORM_REST_API service component. " + "This could result in issue with ambari server start. " + "Please make sure the STORM_REST_API component is deleted " + "from the database by running following commands:\n" + "delete from hostcomponentdesiredstate where component_name='STORM_REST_API';\n" + "delete from hostcomponentstate where component_name='STORM_REST_API';\n" + "delete from servicecomponentdesiredstate where component_name='STORM_REST_API';\n", e); } } } }); } } } } @Inject  UpgradeCatalog210(Injector injector); }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void removeStormRestApiServiceComponent() { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); for (final Cluster cluster : clusterMap.values()) { StackId stackId = cluster.getCurrentStackVersion(); if (stackId != null && stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.2") >= 0) { executeInTransaction(new Runnable() { @Override public void run() { ServiceComponentDesiredStateDAO dao = injector.getInstance(ServiceComponentDesiredStateDAO.class); ServiceComponentDesiredStateEntity entity = dao.findByName(cluster.getClusterId(), "STORM", "STORM_REST_API"); if (entity != null) { EntityManager em = getEntityManagerProvider().get(); CriteriaBuilder cb = em.getCriteriaBuilder(); try { LOG.info("Deleting STORM_REST_API service component."); CriteriaDelete<HostComponentStateEntity> hcsDelete = cb.createCriteriaDelete(HostComponentStateEntity.class); CriteriaDelete<HostComponentDesiredStateEntity> hcdDelete = cb.createCriteriaDelete(HostComponentDesiredStateEntity.class); CriteriaDelete<ServiceComponentDesiredStateEntity> scdDelete = cb.createCriteriaDelete(ServiceComponentDesiredStateEntity.class); Root<HostComponentStateEntity> hcsRoot = hcsDelete.from(HostComponentStateEntity.class); Root<HostComponentDesiredStateEntity> hcdRoot = hcdDelete.from(HostComponentDesiredStateEntity.class); Root<ServiceComponentDesiredStateEntity> scdRoot = scdDelete.from(ServiceComponentDesiredStateEntity.class); hcsDelete.where(cb.equal(hcsRoot.get("componentName"), "STORM_REST_API")); hcdDelete.where(cb.equal(hcdRoot.get("componentName"), "STORM_REST_API")); scdDelete.where(cb.equal(scdRoot.get("componentName"), "STORM_REST_API")); em.createQuery(hcsDelete).executeUpdate(); em.createQuery(hcdDelete).executeUpdate(); em.createQuery(scdDelete).executeUpdate(); } catch (Exception e) { LOG.warn("Error deleting STORM_REST_API service component. " + "This could result in issue with ambari server start. " + "Please make sure the STORM_REST_API component is deleted " + "from the database by running following commands:\n" + "delete from hostcomponentdesiredstate where component_name='STORM_REST_API';\n" + "delete from hostcomponentstate where component_name='STORM_REST_API';\n" + "delete from servicecomponentdesiredstate where component_name='STORM_REST_API';\n", e); } } } }); } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion(); }
UpgradeCatalog210 extends AbstractUpgradeCatalog { protected void removeStormRestApiServiceComponent() { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); for (final Cluster cluster : clusterMap.values()) { StackId stackId = cluster.getCurrentStackVersion(); if (stackId != null && stackId.getStackName().equals("HDP") && VersionUtils.compareVersions(stackId.getStackVersion(), "2.2") >= 0) { executeInTransaction(new Runnable() { @Override public void run() { ServiceComponentDesiredStateDAO dao = injector.getInstance(ServiceComponentDesiredStateDAO.class); ServiceComponentDesiredStateEntity entity = dao.findByName(cluster.getClusterId(), "STORM", "STORM_REST_API"); if (entity != null) { EntityManager em = getEntityManagerProvider().get(); CriteriaBuilder cb = em.getCriteriaBuilder(); try { LOG.info("Deleting STORM_REST_API service component."); CriteriaDelete<HostComponentStateEntity> hcsDelete = cb.createCriteriaDelete(HostComponentStateEntity.class); CriteriaDelete<HostComponentDesiredStateEntity> hcdDelete = cb.createCriteriaDelete(HostComponentDesiredStateEntity.class); CriteriaDelete<ServiceComponentDesiredStateEntity> scdDelete = cb.createCriteriaDelete(ServiceComponentDesiredStateEntity.class); Root<HostComponentStateEntity> hcsRoot = hcsDelete.from(HostComponentStateEntity.class); Root<HostComponentDesiredStateEntity> hcdRoot = hcdDelete.from(HostComponentDesiredStateEntity.class); Root<ServiceComponentDesiredStateEntity> scdRoot = scdDelete.from(ServiceComponentDesiredStateEntity.class); hcsDelete.where(cb.equal(hcsRoot.get("componentName"), "STORM_REST_API")); hcdDelete.where(cb.equal(hcdRoot.get("componentName"), "STORM_REST_API")); scdDelete.where(cb.equal(scdRoot.get("componentName"), "STORM_REST_API")); em.createQuery(hcsDelete).executeUpdate(); em.createQuery(hcdDelete).executeUpdate(); em.createQuery(scdDelete).executeUpdate(); } catch (Exception e) { LOG.warn("Error deleting STORM_REST_API service component. " + "This could result in issue with ambari server start. " + "Please make sure the STORM_REST_API component is deleted " + "from the database by running following commands:\n" + "delete from hostcomponentdesiredstate where component_name='STORM_REST_API';\n" + "delete from hostcomponentstate where component_name='STORM_REST_API';\n" + "delete from servicecomponentdesiredstate where component_name='STORM_REST_API';\n", e); } } } }); } } } } @Inject  UpgradeCatalog210(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion();  }