Exemplo n.º 1
0
  /**
   * Method for registering component manager.
   *
   * @param compMgrId ComponentManager ID.
   * @param body RequestObject. Body should be ComponentManager's objectProperty.
   * @return res ResponseObject. Body should be register objectProperty.
   */
  private Response putComponentManagers(final String compMngId, final ObjectProperty body) {
    // Register the componentManager ID into the HashSet.
    if (!componentMgrsSet.add(compMngId)) {
      // Registered already
      log.warn("ComponentManager is already registerd, ID:{}", compMngId);
      return new Response(Response.CONFLICT, "ComponentManager is already registerd");
    }
    body.setProperty(ObjectProperty.PropertyNames.OBJECT_ID, compMngId);

    this.eventSubscription.addFilter(compMngId, ObjectPropertyChanged.TYPE);
    try {
      this.applyEventSubscription();
    } catch (Exception e) {
      log.error("Recieved Message Exception.", e);
    }

    String componentTypes = body.getProperty(ObjectProperty.PropertyNames.COMPONENT_TYPES);
    if (componentTypes != null) {
      List<String> typeList = Arrays.asList(componentTypes.split(","));
      log.debug("use component_types {} about {} in request body.", typeList, body.getObjectId());

      componentManagerChanged(ComponentManagerChanged.Action.add.name(), null, body);

      updateCreatableComponentType(body.getObjectId(), typeList);
      componentMgrsSet.add(body.getObjectId());
      compMgrsObjProps.put(body.getObjectId(), body);
    } else {
      log.warn("ComponentTypes is not set request body, Comopnent ID:{}", body.getObjectId());
      return new Response(Response.BAD_REQUEST, null);
    }

    log.info("Registerd ComponentManager Object ID:{}", body.getObjectId());
    return new Response(Response.OK, body);
  }
Exemplo n.º 2
0
 private void updateComponentManager(final String id, final ObjectProperty body) {
   compMgrsObjProps.put(id, body);
   if (componentMgrsSet.add(id)) {
     log.warn("ComponentManager is not registerd, ID:{}", id);
     return;
   }
   String componentTypes = body.getProperty(ComponentManager2.ATTR_COMPTYPE);
   if (componentTypes == null) {
     log.warn("ComponentTypes is not set request body, Comopnent ID:{}", id);
     return;
   }
   List<String> typeList = Arrays.asList(componentTypes.split(","));
   log.debug("use component_types {} about {} in request body.", typeList, id);
   updateCreatableComponentType(id, typeList);
 }