@Test public void testUpdateViewInstance() throws Exception { ViewRegistry registry = ViewRegistry.getInstance(); Properties properties = new Properties(); properties.put("p1", "v1"); Configuration ambariConfig = new Configuration(properties); ViewConfig config = ViewConfigTest.getConfig(XML_VALID_INSTANCE); ViewEntity viewEntity = getViewEntity(config, ambariConfig, getClass().getClassLoader(), ""); ViewInstanceEntity viewInstanceEntity = getViewInstanceEntity(viewEntity, config.getInstances().get(0)); ViewInstanceEntity updateInstance = getViewInstanceEntity(viewEntity, config.getInstances().get(0)); expect(viewInstanceDAO.merge(viewInstanceEntity)).andReturn(viewInstanceEntity); expect(viewInstanceDAO.findByName("MY_VIEW{1.0.0}", viewInstanceEntity.getInstanceName())).andReturn(viewInstanceEntity).anyTimes(); replay(viewDAO, viewInstanceDAO, securityHelper); registry.addDefinition(viewEntity); registry.installViewInstance(viewInstanceEntity); Assert.assertTrue(viewInstanceEntity.isVisible()); updateInstance.setLabel("new label"); updateInstance.setDescription("new description"); updateInstance.setVisible(false); registry.updateViewInstance(updateInstance); Collection<ViewInstanceEntity> viewInstanceDefinitions = registry.getInstanceDefinitions(viewEntity); Assert.assertEquals(1, viewInstanceDefinitions.size()); ViewInstanceEntity instanceEntity = viewInstanceDefinitions.iterator().next(); Assert.assertEquals("v2-1", instanceEntity.getProperty("p2").getValue() ); Assert.assertEquals("new label", instanceEntity.getLabel() ); Assert.assertEquals("new description", instanceEntity.getDescription() ); Assert.assertFalse(instanceEntity.isVisible()); Assert.assertEquals(viewInstanceEntity, viewInstanceDefinitions.iterator().next()); verify(viewDAO, viewInstanceDAO, securityHelper); }
public void updateViewInstance(ViewInstanceEntity instanceEntity) throws ValidationException, SystemException { ViewEntity viewEntity = getDefinition(instanceEntity.getViewName()); if (viewEntity != null) { instanceEntity.validate(viewEntity, Validator.ValidationContext.PRE_UPDATE); instanceDAO.merge(instanceEntity); syncViewInstance(instanceEntity); } }
ViewRegistry { public void updateViewInstance(ViewInstanceEntity instanceEntity) throws ValidationException, SystemException { ViewEntity viewEntity = getDefinition(instanceEntity.getViewName()); if (viewEntity != null) { instanceEntity.validate(viewEntity, Validator.ValidationContext.PRE_UPDATE); instanceDAO.merge(instanceEntity); syncViewInstance(instanceEntity); } } }
ViewRegistry { public void updateViewInstance(ViewInstanceEntity instanceEntity) throws ValidationException, SystemException { ViewEntity viewEntity = getDefinition(instanceEntity.getViewName()); if (viewEntity != null) { instanceEntity.validate(viewEntity, Validator.ValidationContext.PRE_UPDATE); instanceDAO.merge(instanceEntity); syncViewInstance(instanceEntity); } } @Inject  ViewRegistry(AmbariEventPublisher publisher); }
ViewRegistry { public void updateViewInstance(ViewInstanceEntity instanceEntity) throws ValidationException, SystemException { ViewEntity viewEntity = getDefinition(instanceEntity.getViewName()); if (viewEntity != null) { instanceEntity.validate(viewEntity, Validator.ValidationContext.PRE_UPDATE); instanceDAO.merge(instanceEntity); syncViewInstance(instanceEntity); } } @Inject  ViewRegistry(AmbariEventPublisher publisher); static void main(String[] args); Collection<ViewEntity> getDefinitions(); ViewEntity getDefinition(String viewName, String version); ViewEntity getDefinition(ResourceTypeEntity resourceTypeEntity); void addDefinition(ViewEntity definition); Collection<ViewInstanceEntity> getInstanceDefinitions(ViewEntity definition); ViewInstanceEntity getInstanceDefinition(String viewName, String version, String instanceName); void addInstanceDefinition(ViewEntity definition, ViewInstanceEntity instanceDefinition); void removeInstanceDefinition(ViewEntity definition, String instanceName); static void initInstance(ViewRegistry singleton); static ViewRegistry getInstance(); Set<SubResourceDefinition> getSubResourceDefinitions(
      String viewName, String version); void readViewArchives(); void readViewArchives(String viewNameRegExp); boolean instanceExists(ViewInstanceEntity instanceEntity); void installViewInstance(ViewInstanceEntity instanceEntity); void updateViewInstance(ViewInstanceEntity instanceEntity); void updateView(ViewInstanceEntity instanceEntity); ViewInstanceEntity getViewInstanceEntity(String viewName, String instanceName); @Transactional void uninstallViewInstance(ViewInstanceEntity instanceEntity); @Transactional void removeInstanceData(ViewInstanceEntity instanceEntity, String key); @Transactional void copyPrivileges(ViewInstanceEntity sourceInstanceEntity,
                             ViewInstanceEntity targetInstanceEntity); void fireEvent(Event event); synchronized void registerListener(Listener listener, String viewName, String viewVersion); synchronized void unregisterListener(Listener listener, String viewName, String viewVersion); boolean hasPermission(PermissionEntity permissionEntity, ResourceEntity resourceEntity, String userName); boolean checkPermission(String viewName, String version, String instanceName, boolean readOnly); boolean checkPermission(ViewInstanceEntity instanceEntity, boolean readOnly); boolean checkAdmin(); boolean includeDefinition(ViewEntity definitionEntity); void setViewInstanceProperties(ViewInstanceEntity instanceEntity, Map<String, String> properties,
                                        ViewConfig viewConfig, ClassLoader classLoader); Cluster getCluster(ViewInstanceDefinition viewInstance); @Subscribe @AllowConcurrentEvents void onAmbariEvent(ServiceInstalledEvent event); @Subscribe void onClusterConfigFinishedEvent(ClusterConfigFinishedEvent event); void readViewArchive(Path path); }
ViewRegistry { public void updateViewInstance(ViewInstanceEntity instanceEntity) throws ValidationException, SystemException { ViewEntity viewEntity = getDefinition(instanceEntity.getViewName()); if (viewEntity != null) { instanceEntity.validate(viewEntity, Validator.ValidationContext.PRE_UPDATE); instanceDAO.merge(instanceEntity); syncViewInstance(instanceEntity); } } @Inject  ViewRegistry(AmbariEventPublisher publisher); static void main(String[] args); Collection<ViewEntity> getDefinitions(); ViewEntity getDefinition(String viewName, String version); ViewEntity getDefinition(ResourceTypeEntity resourceTypeEntity); void addDefinition(ViewEntity definition); Collection<ViewInstanceEntity> getInstanceDefinitions(ViewEntity definition); ViewInstanceEntity getInstanceDefinition(String viewName, String version, String instanceName); void addInstanceDefinition(ViewEntity definition, ViewInstanceEntity instanceDefinition); void removeInstanceDefinition(ViewEntity definition, String instanceName); static void initInstance(ViewRegistry singleton); static ViewRegistry getInstance(); Set<SubResourceDefinition> getSubResourceDefinitions(
      String viewName, String version); void readViewArchives(); void readViewArchives(String viewNameRegExp); boolean instanceExists(ViewInstanceEntity instanceEntity); void installViewInstance(ViewInstanceEntity instanceEntity); void updateViewInstance(ViewInstanceEntity instanceEntity); void updateView(ViewInstanceEntity instanceEntity); ViewInstanceEntity getViewInstanceEntity(String viewName, String instanceName); @Transactional void uninstallViewInstance(ViewInstanceEntity instanceEntity); @Transactional void removeInstanceData(ViewInstanceEntity instanceEntity, String key); @Transactional void copyPrivileges(ViewInstanceEntity sourceInstanceEntity,
                             ViewInstanceEntity targetInstanceEntity); void fireEvent(Event event); synchronized void registerListener(Listener listener, String viewName, String viewVersion); synchronized void unregisterListener(Listener listener, String viewName, String viewVersion); boolean hasPermission(PermissionEntity permissionEntity, ResourceEntity resourceEntity, String userName); boolean checkPermission(String viewName, String version, String instanceName, boolean readOnly); boolean checkPermission(ViewInstanceEntity instanceEntity, boolean readOnly); boolean checkAdmin(); boolean includeDefinition(ViewEntity definitionEntity); void setViewInstanceProperties(ViewInstanceEntity instanceEntity, Map<String, String> properties,
                                        ViewConfig viewConfig, ClassLoader classLoader); Cluster getCluster(ViewInstanceDefinition viewInstance); @Subscribe @AllowConcurrentEvents void onAmbariEvent(ServiceInstalledEvent event); @Subscribe void onClusterConfigFinishedEvent(ClusterConfigFinishedEvent event); void readViewArchive(Path path); static final String API_PREFIX; static final String DEFAULT_AUTO_INSTANCE_URL; }