Package org.apache.ambari.server.orm.entities

Examples of org.apache.ambari.server.orm.entities.ViewInstanceEntity


   */
  public void removeInstanceDefinition(ViewEntity definition, String instanceName) {
    Map<String, ViewInstanceEntity> instanceDefinitions = viewInstanceDefinitions.get(definition);
    if (instanceDefinitions != null) {

      ViewInstanceEntity instanceDefinition = instanceDefinitions.get(instanceName);
      if (instanceDefinition != null) {
        View view = definition.getView();
        if (view != null) {
          view.onDestroy(instanceDefinition);
        }
View Full Code Here


              version + "/" + instanceName);
        }
        instanceEntity.validate(viewEntity);
        instanceDAO.merge(instanceEntity);

        ViewInstanceEntity persistedInstance = instanceDAO.findByName(ViewEntity.getViewName(viewName, version), instanceName);
        if (persistedInstance == null) {
          String message = "Instance  " + instanceEntity.getViewName() + " can not be found.";

          LOG.error(message);
          throw new IllegalStateException(message);
        }
        instanceEntity.setViewInstanceId(persistedInstance.getViewInstanceId());

        try {
          // bind the view instance to a view
          bindViewInstance(viewEntity, instanceEntity);
        } catch (Exception e) {
View Full Code Here

    if (viewEntity != null) {
      String instanceName = instanceEntity.getName();
      String viewName     = viewEntity.getCommonName();
      String version      = viewEntity.getVersion();

      ViewInstanceEntity entity = getInstanceDefinition(viewName, version, instanceName);

      if (entity != null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Updating view instance " + viewName + "/" +
              version + "/" + instanceName);
        }
        entity.setLabel(instanceEntity.getLabel());
        entity.setDescription(instanceEntity.getDescription());
        entity.setVisible(instanceEntity.isVisible());
        entity.setProperties(instanceEntity.getProperties());
        entity.setData(instanceEntity.getData());

        instanceEntity.validate(viewEntity);
        instanceDAO.merge(entity);
      }
    }
View Full Code Here

  }

  // create a new view instance definition
  protected ViewInstanceEntity createViewInstanceDefinition(ViewEntity viewDefinition, InstanceConfig instanceConfig)
      throws ClassNotFoundException, IllegalStateException {
    ViewInstanceEntity viewInstanceDefinition =
        new ViewInstanceEntity(viewDefinition, instanceConfig);

    for (PropertyConfig propertyConfig : instanceConfig.getProperties()) {
      viewInstanceDefinition.putProperty(propertyConfig.getKey(), propertyConfig.getValue());
    }
    viewInstanceDefinition.validate(viewDefinition);

    bindViewInstance(viewDefinition, viewInstanceDefinition);
    return viewInstanceDefinition;
  }
View Full Code Here

    // make sure that each instance of the view in the db is reflected in the given view
    for (ViewInstanceEntity persistedInstance : persistedView.getInstances()){
      String instanceName = persistedInstance.getName();

      ViewInstanceEntity instance =
          view.getInstanceDefinition(instanceName);

      instanceEntityMap.remove(instanceName);

      // if the persisted instance is not in the registry ...
      if (instance == null) {
        // ... create and add it
        instance = new ViewInstanceEntity(view, instanceName);
        bindViewInstance(view, instance);
        instanceDefinitions.add(instance);
      }
      instance.setViewInstanceId(persistedInstance.getViewInstanceId());

      // apply the persisted overrides to the in-memory instance
      instance.setLabel(persistedInstance.getLabel());
      instance.setDescription(persistedInstance.getDescription());
      instance.setVisible(persistedInstance.isVisible());
      instance.setData(persistedInstance.getData());
      instance.setProperties(persistedInstance.getProperties());
      instance.setEntities(persistedInstance.getEntities());
    }

    // these instances appear in the archive but have been deleted
    // from the db... remove them from the registry
    for (ViewInstanceEntity instance : instanceEntityMap.values()) {
      view.removeInstanceDefinition(instance.getName());
      instanceDefinitions.remove(instance);
    }
  }
View Full Code Here

public class ViewContextImplTest {
  @Test
  public void testGetViewName() throws Exception {
    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
    ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
    ViewInstanceEntity viewInstanceDefinition = new ViewInstanceEntity(viewDefinition, instanceConfig);
    ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class);

    ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition, viewRegistry);

    Assert.assertEquals("MY_VIEW", viewContext.getViewName());
View Full Code Here

  @Test
  public void testGetInstanceName() throws Exception {
    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
    ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
    ViewInstanceEntity viewInstanceDefinition = new ViewInstanceEntity(viewDefinition, instanceConfig);
    ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class);

    ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition, viewRegistry);

    Assert.assertEquals("INSTANCE1", viewContext.getInstanceName());
View Full Code Here

  @Test
  public void testGetProperties() throws Exception {
    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
    ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
    ViewInstanceEntity viewInstanceDefinition = new ViewInstanceEntity(viewDefinition, instanceConfig);
    ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class);
    viewInstanceDefinition.putProperty("p1", "v1");
    viewInstanceDefinition.putProperty("p2", "v2");
    viewInstanceDefinition.putProperty("p3", "v3");

    ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition, viewRegistry);

    Map<String, String> properties = viewContext.getProperties();
    Assert.assertEquals(3, properties.size());
View Full Code Here

  @Test
  public void testGetResourceProvider() throws Exception {
    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
    ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
    ViewInstanceEntity viewInstanceDefinition = new ViewInstanceEntity(viewDefinition, instanceConfig);
    ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class);

    ResourceProvider provider = createNiceMock(ResourceProvider.class);
    Resource.Type type = new Resource.Type("MY_VIEW{1.0.0}/myType");

    viewInstanceDefinition.addResourceProvider(type, provider);

    ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition, viewRegistry);

    Assert.assertEquals(provider, viewContext.getResourceProvider("myType"));
  }
View Full Code Here

  @Test
  public void testGetURLStreamProvider() throws Exception {
    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
    ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
    ViewInstanceEntity viewInstanceDefinition = new ViewInstanceEntity(viewDefinition, instanceConfig);
    ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class);

    ResourceProvider provider = createNiceMock(ResourceProvider.class);
    Resource.Type type = new Resource.Type("MY_VIEW/myType");

    viewInstanceDefinition.addResourceProvider(type, provider);

    ViewContextImpl viewContext = new ViewContextImpl(viewInstanceDefinition, viewRegistry);

    Assert.assertNotNull(viewContext.getURLStreamProvider());
  }
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.orm.entities.ViewInstanceEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.