private void syncView(ViewEntity view,
                        Set<ViewInstanceEntity> instanceDefinitions)
      throws Exception {

    String viewName = view.getName();
    ViewEntity persistedView = viewDAO.findByName(viewName);

    if (LOG.isDebugEnabled()) {
      LOG.debug("Syncing view {}.", viewName);
    }

    // if the view is not yet persisted ...
    if (persistedView == null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Creating view {}.", viewName);
      }

      // create an admin resource type to represent this view
      ResourceTypeEntity resourceType = resourceTypeDAO.merge(view.getResourceType());

      for (ViewInstanceEntity instance : view.getInstances()) {
        instance.setResource(createViewInstanceResource(resourceType));
      }
      // ... merge the view
      view.setResourceType(resourceType);
      persistedView = viewDAO.merge(view);
    }

    view.setResourceType(persistedView.getResourceType());
    view.setPermissions(persistedView.getPermissions());

    // 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);

      // if the persisted instance is not in the view ...
      if (instance == null) {
        if (persistedInstance.isXmlDriven()) {
          // this instance was persisted from an earlier view.xml but has been removed...
          // remove it from the db
          instanceDAO.remove(persistedInstance);
        } else {
          // this instance was not specified in the view.xml but was added through the API...
          // bind it to the view and add it to the registry
          instanceDAO.merge(persistedInstance);
          bindViewInstance(view, persistedInstance);
          instanceDefinitions.add(persistedInstance);
        }
      } else {
        syncViewInstance(instance, persistedInstance);
      }
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("Syncing view {} complete.", viewName);
    }
  }
Sync given view with data in DB. Ensures that view data in DB is updated,
all instances changes from xml config are reflected to DB

@param view                view config from xml
@param instanceDefinitions view instances from xml
@throws Exception if the view can not be synced
ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java