@Test public void testUpgradeCapSchedulerView() throws SQLException, MaskException { final RemoteAmbariClusterDAO clusterDAO = createNiceMock(RemoteAmbariClusterDAO.class); final ViewInstanceDAO instanceDAO = createNiceMock(ViewInstanceDAO.class); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class)); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); bind(RemoteAmbariClusterDAO.class).toInstance(clusterDAO); bind(ViewInstanceDAO.class).toInstance(instanceDAO); bind(PasswordEncoder.class).toInstance(createNiceMock(PasswordEncoder.class)); bind(HookContextFactory.class).toInstance(createMock(HookContextFactory.class)); bind(HookService.class).toInstance(createMock(HookService.class)); } }); List<ViewInstanceEntity> instances = new ArrayList<ViewInstanceEntity>(); ViewInstanceEntity instance1 = createNiceMock(ViewInstanceEntity.class); expect(instance1.getViewName()).andReturn("CAPACITY-SCHEDULER{1.0.0}"); expect(instance1.getClusterHandle()).andReturn(null); instances.add(instance1); Map<String,String> propertyMap = new HashMap<String,String>(); String url = "url"; String username = "user"; String password = "password"; propertyMap.put("ambari.server.url",url); propertyMap.put("ambari.server.username",username); propertyMap.put("ambari.server.password",new DefaultMasker().mask(password)); expect(instance1.getPropertyMap()).andReturn(propertyMap); expect(instance1.getName()).andReturn("instance"); expect(instanceDAO.findAll()).andReturn(instances); Capture<RemoteAmbariClusterEntity> clusterEntityCapture = newCapture(); clusterDAO.save(capture(clusterEntityCapture)); instance1.setClusterType(ClusterType.REMOTE_AMBARI); instance1.setClusterHandle(null); expect(instanceDAO.merge(eq(instance1))).andReturn(instance1); replay(clusterDAO, instanceDAO, instance1); mockInjector.getInstance(UpgradeCatalog240.class).upgradeCapSchedulerView(); assertEquals("instance-cluster", clusterEntityCapture.getValue().getName()); assertEquals(url, clusterEntityCapture.getValue().getUrl()); assertEquals(username, clusterEntityCapture.getValue().getUsername()); assertEquals(password, clusterEntityCapture.getValue().getPassword()); verify(clusterDAO, instanceDAO, instance1); }
protected void upgradeCapSchedulerView() throws SQLException { String capSchedulerViewName = "CAPACITY-SCHEDULER{1.0.0}"; RemoteAmbariClusterDAO remoteClusterDAO = injector.getInstance(RemoteAmbariClusterDAO.class); ViewInstanceDAO instanceDAO = injector.getInstance(ViewInstanceDAO.class); List<ViewInstanceEntity> instances = instanceDAO.findAll(); for (ViewInstanceEntity instance : instances) { if (instance.getViewName().equals(capSchedulerViewName) && instance.getClusterHandle() == null) { RemoteAmbariClusterEntity clusterEntity = new RemoteAmbariClusterEntity(); clusterEntity.setName(instance.getName() + "-cluster"); Map<String, String> propertyMap = instance.getPropertyMap(); String url = propertyMap.get("ambari.server.url"); String password = propertyMap.get("ambari.server.password"); String username = propertyMap.get("ambari.server.username"); if (StringUtils.isEmpty(url) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { LOG.info("One of url, username, password is empty. Skipping upgrade for View Instance {}.", instance.getName()); continue; } clusterEntity.setUrl(url); clusterEntity.setUsername(username); try { clusterEntity.setPassword(new DefaultMasker().unmask(password)); } catch (MaskException e) { } remoteClusterDAO.save(clusterEntity); instance.setClusterHandle(clusterEntity.getId()); instance.setClusterType(ClusterType.REMOTE_AMBARI); instanceDAO.merge(instance); } } }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void upgradeCapSchedulerView() throws SQLException { String capSchedulerViewName = "CAPACITY-SCHEDULER{1.0.0}"; RemoteAmbariClusterDAO remoteClusterDAO = injector.getInstance(RemoteAmbariClusterDAO.class); ViewInstanceDAO instanceDAO = injector.getInstance(ViewInstanceDAO.class); List<ViewInstanceEntity> instances = instanceDAO.findAll(); for (ViewInstanceEntity instance : instances) { if (instance.getViewName().equals(capSchedulerViewName) && instance.getClusterHandle() == null) { RemoteAmbariClusterEntity clusterEntity = new RemoteAmbariClusterEntity(); clusterEntity.setName(instance.getName() + "-cluster"); Map<String, String> propertyMap = instance.getPropertyMap(); String url = propertyMap.get("ambari.server.url"); String password = propertyMap.get("ambari.server.password"); String username = propertyMap.get("ambari.server.username"); if (StringUtils.isEmpty(url) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { LOG.info("One of url, username, password is empty. Skipping upgrade for View Instance {}.", instance.getName()); continue; } clusterEntity.setUrl(url); clusterEntity.setUsername(username); try { clusterEntity.setPassword(new DefaultMasker().unmask(password)); } catch (MaskException e) { } remoteClusterDAO.save(clusterEntity); instance.setClusterHandle(clusterEntity.getId()); instance.setClusterType(ClusterType.REMOTE_AMBARI); instanceDAO.merge(instance); } } } }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void upgradeCapSchedulerView() throws SQLException { String capSchedulerViewName = "CAPACITY-SCHEDULER{1.0.0}"; RemoteAmbariClusterDAO remoteClusterDAO = injector.getInstance(RemoteAmbariClusterDAO.class); ViewInstanceDAO instanceDAO = injector.getInstance(ViewInstanceDAO.class); List<ViewInstanceEntity> instances = instanceDAO.findAll(); for (ViewInstanceEntity instance : instances) { if (instance.getViewName().equals(capSchedulerViewName) && instance.getClusterHandle() == null) { RemoteAmbariClusterEntity clusterEntity = new RemoteAmbariClusterEntity(); clusterEntity.setName(instance.getName() + "-cluster"); Map<String, String> propertyMap = instance.getPropertyMap(); String url = propertyMap.get("ambari.server.url"); String password = propertyMap.get("ambari.server.password"); String username = propertyMap.get("ambari.server.username"); if (StringUtils.isEmpty(url) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { LOG.info("One of url, username, password is empty. Skipping upgrade for View Instance {}.", instance.getName()); continue; } clusterEntity.setUrl(url); clusterEntity.setUsername(username); try { clusterEntity.setPassword(new DefaultMasker().unmask(password)); } catch (MaskException e) { } remoteClusterDAO.save(clusterEntity); instance.setClusterHandle(clusterEntity.getId()); instance.setClusterType(ClusterType.REMOTE_AMBARI); instanceDAO.merge(instance); } } } @Inject  UpgradeCatalog240(Injector injector); }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void upgradeCapSchedulerView() throws SQLException { String capSchedulerViewName = "CAPACITY-SCHEDULER{1.0.0}"; RemoteAmbariClusterDAO remoteClusterDAO = injector.getInstance(RemoteAmbariClusterDAO.class); ViewInstanceDAO instanceDAO = injector.getInstance(ViewInstanceDAO.class); List<ViewInstanceEntity> instances = instanceDAO.findAll(); for (ViewInstanceEntity instance : instances) { if (instance.getViewName().equals(capSchedulerViewName) && instance.getClusterHandle() == null) { RemoteAmbariClusterEntity clusterEntity = new RemoteAmbariClusterEntity(); clusterEntity.setName(instance.getName() + "-cluster"); Map<String, String> propertyMap = instance.getPropertyMap(); String url = propertyMap.get("ambari.server.url"); String password = propertyMap.get("ambari.server.password"); String username = propertyMap.get("ambari.server.username"); if (StringUtils.isEmpty(url) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { LOG.info("One of url, username, password is empty. Skipping upgrade for View Instance {}.", instance.getName()); continue; } clusterEntity.setUrl(url); clusterEntity.setUsername(username); try { clusterEntity.setPassword(new DefaultMasker().unmask(password)); } catch (MaskException e) { } remoteClusterDAO.save(clusterEntity); instance.setClusterHandle(clusterEntity.getId()); instance.setClusterType(ClusterType.REMOTE_AMBARI); instanceDAO.merge(instance); } } } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void upgradeCapSchedulerView() throws SQLException { String capSchedulerViewName = "CAPACITY-SCHEDULER{1.0.0}"; RemoteAmbariClusterDAO remoteClusterDAO = injector.getInstance(RemoteAmbariClusterDAO.class); ViewInstanceDAO instanceDAO = injector.getInstance(ViewInstanceDAO.class); List<ViewInstanceEntity> instances = instanceDAO.findAll(); for (ViewInstanceEntity instance : instances) { if (instance.getViewName().equals(capSchedulerViewName) && instance.getClusterHandle() == null) { RemoteAmbariClusterEntity clusterEntity = new RemoteAmbariClusterEntity(); clusterEntity.setName(instance.getName() + "-cluster"); Map<String, String> propertyMap = instance.getPropertyMap(); String url = propertyMap.get("ambari.server.url"); String password = propertyMap.get("ambari.server.password"); String username = propertyMap.get("ambari.server.username"); if (StringUtils.isEmpty(url) || StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { LOG.info("One of url, username, password is empty. Skipping upgrade for View Instance {}.", instance.getName()); continue; } clusterEntity.setUrl(url); clusterEntity.setUsername(username); try { clusterEntity.setPassword(new DefaultMasker().unmask(password)); } catch (MaskException e) { } remoteClusterDAO.save(clusterEntity); instance.setClusterHandle(clusterEntity.getId()); instance.setClusterType(ClusterType.REMOTE_AMBARI); instanceDAO.merge(instance); } } } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String DESIRED_VERSION_COLUMN_NAME; static final String BLUEPRINT_SETTING_TABLE; static final String BLUEPRINT_NAME_COL; static final String SETTING_NAME_COL; static final String SETTING_DATA_COL; static final String ID; static final String BLUEPRINT_TABLE; static final String VIEWINSTANCE_TABLE; static final String SHORT_URL_COLUMN; static final String CLUSTER_HANDLE_COLUMN; static final String REQUESTSCHEDULE_TABLE; static final String AUTHENTICATED_USER_ID_COLUMN; static final String TIMELINE_METRICS_SINK_COLLECTION_PERIOD; static final String ONE_DIR_PER_PARITION_PROPERTY; static final String VIEWURL_TABLE; static final String URL_ID_COLUMN; static final String PRECISION_TABLE_TTL_PROPERTY; static final String CLUSTER_SECOND_TABLE_TTL_PROPERTY; static final String CLUSTER_TYPE_COLUMN; static final String REMOTE_AMBARI_CLUSTER_TABLE; static final String REMOTE_AMBARI_CLUSTER_SERVICE_TABLE; static final String CLUSTER_ID; static final String SERVICE_NAME; static final String CLUSTER_NAME; }