public ManagedElement getLocalElement(String managed_element_uuid) {
   ManagedElement me = agent.getRuntimeModel().getManagedElement(managed_element_uuid);
   if (me != null) return me;
   else {
     for (ManagedElement unme : agent.getUnmanagedElements()) {
       if (unme.getUUID().equalsIgnoreCase(managed_element_uuid)) {
         return unme;
       }
     }
   }
   return null;
 }
Exemplo n.º 2
0
  /**
   * Apply the objective constraint. This should modify the two elements in relation!
   *
   * @param subjectVariable
   * @param objectVariable
   * @return
   */
  public boolean performObjective(
      CubeAgent agent, Variable subjectVariable, Variable objectVariable) {
    Object instance1_uuid = subjectVariable.getValue();
    Object instance2_uuid = objectVariable.getValue();

    if (instance1_uuid != null && instance2_uuid != null) {
      RuntimeModelController rmController = agent.getRuntimeModelController();
      if (rmController != null) {
        try {
          String scope_id =
              rmController.getPropertyValue(instance1_uuid.toString(), Scope.CORE_SCOPE_ID);
          if (rmController.addReferencedElement(
              instance1_uuid.toString(), Scope.CORE_SCOPE_MASTER, instance2_uuid.toString())) {
            if (rmController.addReferencedElement(
                instance2_uuid.toString(), scope_id, instance1_uuid.toString())) {
              return true;
            }
          }
        } catch (InvalidNameException ex) {
          ex.printStackTrace();
        }
      }
    }
    return false;
  }
  public boolean addProperty(String managed_element_uuid, String name, String value)
      throws PropertyExistException, InvalidNameException {
    ManagedElement me1 = getLocalElement(managed_element_uuid);
    if (me1 != null) {
      return me1.addProperty(name, value);
    } else {
      String auri = agent.getExternalAgentUri(managed_element_uuid);
      if (auri != null) {
        CMessage msg = new CMessage();
        msg.setTo(auri);
        msg.setObject("runtimemodel");
        msg.setBody("addProperty");
        msg.addHeader("uuid", managed_element_uuid);
        msg.addHeader("name", name);
        msg.addHeader("value", value);
        try {
          CMessage resultmsg = sendAndWait(msg);
          if (resultmsg != null) {
            if (resultmsg.getBody() != null) {
              if (resultmsg.getBody().toString().equalsIgnoreCase("true")) {
                return true;
              }
            }
          }
        } catch (TimeOutException e) {
          e.printStackTrace();
        }
      }
    }

    return false; // To change body of implemented methods use File | Settings | File Templates.
  }
 public String getPropertyValue(String managed_element_uuid, String name) {
   ManagedElement me1 = getLocalElement(managed_element_uuid);
   if (me1 != null) {
     // System.out.println(".... get property value (local) of element: " + managed_element_uuid);
     return me1.getProperty(name);
   } else {
     // System.out.println(".... get property value (remote) of element: " + managed_element_uuid);
     String auri = agent.getExternalAgentUri(managed_element_uuid);
     if (auri != null) {
       CMessage msg = new CMessage();
       msg.setTo(auri);
       msg.setObject("runtimemodel");
       msg.setBody("getPropertyValue");
       msg.addHeader("uuid", managed_element_uuid);
       msg.addHeader("name", name);
       try {
         CMessage resultmsg = sendAndWait(msg);
         if (resultmsg != null) {
           if (resultmsg.getBody() != null) {
             return resultmsg.getBody().toString();
           }
         }
       } catch (TimeOutException e) {
         e.printStackTrace();
       }
     } else {
       System.out.println(
           ".... get property value: impossible to find agent uri of instance "
               + managed_element_uuid);
     }
   }
   return null;
 }
 public boolean hasReferencedElement(
     String managed_element_uuid, String reference_name, String referenced_element_uuri) {
   ManagedElement me1 = getLocalElement(managed_element_uuid);
   if (me1 != null) {
     Reference r = me1.getReference(reference_name);
     if (r != null) {
       return r.hasReferencedElement(referenced_element_uuri);
     }
   } else {
     String auri = agent.getExternalAgentUri(managed_element_uuid);
     if (auri != null) {
       CMessage msg = new CMessage();
       msg.setTo(auri);
       msg.setObject("runtimemodel");
       msg.setBody("hasReferencedElement");
       msg.addHeader("uuid", managed_element_uuid);
       msg.addHeader("name", reference_name);
       msg.addHeader("refuuid", referenced_element_uuri);
       try {
         CMessage resultmsg = sendAndWait(msg);
         if (resultmsg != null) {
           if (resultmsg.getBody() != null) {
             if (resultmsg.getBody().toString().equalsIgnoreCase("true")) {
               return true;
             }
           }
         }
       } catch (TimeOutException e) {
         e.printStackTrace();
       }
     }
   }
   return false;
 }
 public ManagedElement getElement(String managed_element_uuid) {
   String auri = agent.getExternalAgentUri(managed_element_uuid);
   if (auri != null) {
     return getRemoteElement(managed_element_uuid);
   } else {
     return getLocalElement(managed_element_uuid);
   }
   // return null;
 }
Exemplo n.º 7
0
 public boolean check(CubeAgent agent, Variable subjectVariable, Variable objectVariable) {
   Object instance1_uuid = subjectVariable.getValue();
   Object instance2_uuid = objectVariable.getValue();
   if (instance1_uuid != null && instance2_uuid != null) {
     RuntimeModelController rmController = agent.getRuntimeModelController();
     if (rmController != null) {
       if (rmController.hasReferencedElement(
           instance1_uuid.toString(), Scope.CORE_SCOPE_MASTER, instance2_uuid.toString())) {
         return true;
       }
     }
   }
   return false;
 }
Exemplo n.º 8
0
 public void init(CubeAgent agent, Variable subjectVariable, Variable objectVariable) {
   Object instance1_uuid = subjectVariable.getValue();
   if (instance1_uuid != null) {
     RuntimeModelController rmController = agent.getRuntimeModelController();
     if (rmController != null) {
       List<String> tmp =
           rmController.getReferencedElements(instance1_uuid.toString(), Scope.CORE_SCOPE_MASTER);
       for (String s :
           rmController.getReferencedElements(
               instance1_uuid.toString(), Scope.CORE_SCOPE_MASTER)) {
         objectVariable.setValue(s);
       }
     }
   }
 }
 public boolean addReferencedElement(
     String managed_element_uuid,
     String reference_name,
     boolean onlyone,
     String referenced_element_uuid)
     throws InvalidNameException {
   ManagedElement me1 = getLocalElement(managed_element_uuid);
   if (me1 != null) {
     // System.out.println("add Local Reference Element ...");
     Reference r = me1.getReference(reference_name);
     if (r == null) {
       // System.out.println("Reference '"+reference_name+"' does not exists! we will create it!");
       r = me1.addReference(reference_name, onlyone);
     }
     if (r != null) {
       r.addReferencedElement(referenced_element_uuid);
       return true;
     }
   } else {
     // System.out.println("add Remote Reference Element ...");
     String auri = agent.getExternalAgentUri(managed_element_uuid);
     if (auri != null) {
       CMessage msg = new CMessage();
       msg.setTo(auri);
       msg.setObject("runtimemodel");
       msg.setBody("addReferencedElement");
       msg.addHeader("uuid", managed_element_uuid);
       msg.addHeader("name", reference_name);
       msg.addHeader("onlyone", onlyone == true ? "true" : "false");
       msg.addHeader("refuuid", referenced_element_uuid);
       try {
         CMessage resultmsg = sendAndWait(msg);
         if (resultmsg != null) {
           if (resultmsg.getBody() != null) {
             if (resultmsg.getBody().toString().equalsIgnoreCase("true")) {
               return true;
             }
           }
         }
       } catch (TimeOutException e) {
         e.printStackTrace();
       }
     } else {
       System.out.println("External agent of element '" + managed_element_uuid + "' not found!");
     }
   }
   return false;
 }
  public List<String> getReferencedElements(String managed_element_uuid, String reference_name) {

    List<String> result = new ArrayList<String>();
    ManagedElement me1 = getLocalElement(managed_element_uuid);
    if (me1 != null) {
      Reference r = me1.getReference(reference_name);
      if (r != null) {
        return r.getReferencedElements();
      } else {
        // System.out.println("CONTROLLER: no reference with name: " + reference_name);
      }
    } else {
      String auri = agent.getExternalAgentUri(managed_element_uuid);
      if (auri != null) {
        CMessage msg = new CMessage();
        msg.setTo(auri);
        msg.setObject("runtimemodel");
        msg.setBody("getReferencedElements");
        msg.addHeader("uuid", managed_element_uuid);
        msg.addHeader("name", reference_name);
        try {
          CMessage resultmsg = sendAndWait(msg);
          if (resultmsg != null) {
            if (resultmsg.getBody() != null) {
              String[] tmp = resultmsg.getBody().toString().split(",");
              for (int i = 0; i < tmp.length; i++) {
                if (tmp[i] != null && tmp[i].length() > 0) {
                  String[] tmp2 = tmp[i].split("###");
                  String agenturi = tmp2[0];
                  String elementuuid = tmp2[1];
                  if (!agenturi.equalsIgnoreCase(getCubeAgent().getUri())) {
                    this.agent.addExternalElement(elementuuid, agenturi);
                  }
                  result.add(elementuuid);
                }
              }
            }
          }
        } catch (TimeOutException e) {
          e.printStackTrace();
        }
      }
    }
    return result;
  }
Exemplo n.º 11
0
  /**
   * Find value from object variable.
   *
   * @param subjectVariable
   * @param objectVariable
   * @return
   */
  public String find(CubeAgent agent, Variable subjectVariable, Variable objectVariable) {
    Object instance2_uuid = objectVariable.getValue();

    if (instance2_uuid != null) {
      RuntimeModelController rmController = agent.getRuntimeModelController();
      if (rmController != null) {
        List<String> sleaders =
            rmController.getReferencedElements(
                instance2_uuid.toString(), subjectVariable.getProperty(Scope.CORE_SCOPE_ID));
        for (String s : sleaders) {
          if (!subjectVariable.hasValue(s)) {
            return s;
          }
        }
      }
    }
    return null;
  }
 public ManagedElement getRemoteElement(String managed_element_uuid) {
   String auri = agent.getExternalAgentUri(managed_element_uuid);
   if (auri != null) {
     CMessage msg = new CMessage();
     msg.setTo(auri);
     msg.setObject("runtimemodel");
     msg.setBody("getRemoteElement");
     msg.addHeader("uuid", managed_element_uuid);
     try {
       CMessage resultmsg = sendAndWait(msg);
       if (resultmsg != null) {
         return resultmsg.getAttachement();
       }
     } catch (TimeOutException e) {
       e.printStackTrace();
     }
   }
   return null;
 }
Exemplo n.º 13
0
  public RMMonitoringPlugin(CubeAgent agent, PluginFactory bundle, Properties properties) {
    super(agent, bundle, properties);

    gui = new MonitorGUI(agent);

    agent
        .getRuntimeModel()
        .addListener(
            new RuntimeModelListener() {
              public void update(RuntimeModel rm, Notification notification) {
                if (notification.getNotificationType()
                    == RuntimeModelListener.UPDATED_RUNTIMEMODEL) {
                  /*
                  Object instance = notification.getNewValue();
                  if (instance != null && instance instanceof ManagedElement) {
                       gui.addNode((ManagedElement)instance);
                  }
                  */
                  gui.updateGraph();
                }
              }
            });
  }