Class ComponentUtilImpl

java.lang.Object
io.openems.edge.core.appmanager.ComponentUtilImpl
All Implemented Interfaces:
ComponentUtil

public class ComponentUtilImpl extends Object implements ComponentUtil
  • Constructor Details

    • ComponentUtilImpl

      public ComponentUtilImpl(ComponentManager componentManager, org.osgi.service.cm.ConfigurationAdmin cm)
  • Method Details

    • equals

      public static boolean equals(com.google.gson.JsonElement expected, com.google.gson.JsonElement actual)
      Validates if the 'actual' matches the 'expected' value.
      Parameters:
      expected - the expected value
      actual - the actual value
      Returns:
      true if they match
    • equals

      public static boolean equals(List<NetworkInterface<?>> interfaces, List<NetworkInterface<?>> otherInterfaces)
      Validates if the 'interfaces' matches the 'otherInterfaces'.
      Parameters:
      interfaces - the first interfaces
      otherInterfaces - the second interfaces
      Returns:
      true if they match
    • getInterfaces

      public static List<NetworkInterface<?>> getInterfaces(com.google.gson.JsonObject json) throws OpenemsError.OpenemsNamedException
      parses all interfaces from the given JsonObject.
      Parameters:
      json - the JsonObject that contains the interfaces
      Returns:
      the parsed interfaces
      Throws:
      OpenemsError.OpenemsNamedException - on error
    • getInterfaces

      public List<NetworkInterface<?>> getInterfaces() throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentUtil
      Gets the interfaces of the currently active network settings.
      Specified by:
      getInterfaces in interface ComponentUtil
      Returns:
      all interfaces in the host configuration
      Throws:
      OpenemsError.OpenemsNamedException - on error
    • isSameConfiguration

      public static boolean isSameConfiguration(List<String> errors, EdgeConfig.Component expectedComponent, EdgeConfig.Component actualComponent)
      Checks if the expectedComonents match with the actualComponent.
      Parameters:
      errors - list if something does not match
      expectedComponent - the expected component
      actualComponent - the actual existing component
      Returns:
      true if the configurations are the same
    • isSameConfigurationWithoutAlias

      public static boolean isSameConfigurationWithoutAlias(List<String> errors, EdgeConfig.Component expectedComponent, EdgeConfig.Component actualComponent)
      Checks if the expectedComonents match with the actualComponent without checking the alias.
      Parameters:
      errors - list if something does not match
      expectedComponent - the expected component
      actualComponent - the actual existing component
      Returns:
      true if the configurations are the same
    • isSameConfigurationWithoutId

      public static boolean isSameConfigurationWithoutId(List<String> errors, EdgeConfig.Component expectedComponent, EdgeConfig.Component actualComponent)
      Checks if the expectedComonents match with the actualComponent without checking the Component-ID.
      Parameters:
      errors - list if something does not match
      expectedComponent - the expected component
      actualComponent - the actual existing component
      Returns:
      true if the configurations are the same
    • isSameConfigurationWithoutIdAndAlias

      public static boolean isSameConfigurationWithoutIdAndAlias(List<String> errors, EdgeConfig.Component expectedComponent, EdgeConfig.Component actualComponent)
      Checks if the expectedComonents match with the actualComponent without checking the Component-ID and the alias.
      Parameters:
      errors - list if something does not match
      expectedComponent - the expected component
      actualComponent - the actual existing component
      Returns:
      true if the configurations are the same
    • order

      public static List<EdgeConfig.Component> order(List<EdgeConfig.Component> components)
      orders the list so components that need another component are coming after the needed component.
      Parameters:
      components - the component list
      Returns:
      an ordered copy of the list
    • anyComponentUses

      public boolean anyComponentUses(String value, List<String> ignoreIds)
      Description copied from interface: ComponentUtil
      Checks if any component has the given String in its configuration.
      Specified by:
      anyComponentUses in interface ComponentUtil
      Parameters:
      value - that no component should have
      ignoreIds - the id s of components which configuration should be ignored
      Returns:
      true if a component has the given String in its configuration
    • getAllRelays

      public List<ComponentUtilImpl.Relay> getAllRelays()
      Description copied from interface: ComponentUtil
      Gets a list of current Relays. e. g. 'io0/Relay1'
      Specified by:
      getAllRelays in interface ComponentUtil
      Returns:
      a list of Relays
    • getAvailableRelays

      public List<ComponentUtilImpl.Relay> getAvailableRelays()
      Description copied from interface: ComponentUtil
      Gets a list of currently available Relays of IOs which are not used by any component. e. g. 'io0/Relay1'
      Specified by:
      getAvailableRelays in interface ComponentUtil
      Returns:
      a list of available Relays
    • getAvailableRelays

      public List<ComponentUtilImpl.Relay> getAvailableRelays(List<String> ignoreIds)
      Description copied from interface: ComponentUtil
      Gets a list of currently available Relays of IOs which are not used by any component. like 'io0/Relay1'
      Specified by:
      getAvailableRelays in interface ComponentUtil
      Parameters:
      ignoreIds - the Component-IDs that should be ignored
      Returns:
      a list of available Relays
    • getAvailableRelays

      public List<String> getAvailableRelays(String ioId) throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentUtil
      Gets a list of currently available Relays of given IO which are not used by any component. like 'io0/Relay1'
      Specified by:
      getAvailableRelays in interface ComponentUtil
      Parameters:
      ioId - the Component-ID of the DigitalOutput
      Returns:
      a list of available Relays
      Throws:
      OpenemsError.OpenemsNamedException - if the io was not found
    • getAvailableRelays

      public List<String> getAvailableRelays(String ioId, List<String> ignoreIds) throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentUtil
      Gets a list of currently available Relays of given IO which are not used by any component. e. g. 'io0/Relay1'
      Specified by:
      getAvailableRelays in interface ComponentUtil
      Parameters:
      ioId - the Component-ID of the DigitalOutput
      ignoreIds - the Component-IDs that should be ignored
      Returns:
      a list of available Relays
      Throws:
      OpenemsError.OpenemsNamedException - if the io was not found
    • getComponentByConfig

      public EdgeConfig.Component getComponentByConfig(EdgeConfig.Component component)
      Description copied from interface: ComponentUtil
      Searches a component with the given component configuration.
      Specified by:
      getComponentByConfig in interface ComponentUtil
      Parameters:
      component - with the configuration to be searched for
      Returns:
      the found component or null if not found
    • getEnabledComponentsOfStartingId

      public <T extends OpenemsComponent> List<T> getEnabledComponentsOfStartingId(String id)
      Description copied from interface: ComponentUtil
      Gets the enabled Components with the starting id.
      Specified by:
      getEnabledComponentsOfStartingId in interface ComponentUtil
      Type Parameters:
      T - the type to which the components should be assignable to
      Parameters:
      id - the starting id of the components
      Returns:
      a list of found components
    • getEnabledComponentsOfType

      public <T extends OpenemsComponent> List<T> getEnabledComponentsOfType(Class<T> clazz)
      Description copied from interface: ComponentUtil
      Gets the enabled Components of a Type.

      the method 'this.componentManager.getEnabledComponentsOfType(clazz)' does not return the component if the given class is an interface and the component has the interface implemented

      Specified by:
      getEnabledComponentsOfType in interface ComponentUtil
      Type Parameters:
      T - the type to which the components should be assignable to
      Parameters:
      clazz - to which the component should be assignable to
      Returns:
      a list of found components
    • getNextAvailableId

      public String getNextAvailableId(String baseName, int startingNumber, List<String> componentIds)
      Description copied from interface: ComponentUtil
      Gets the next available id with the baseName starting with the given startingNumber.
      Specified by:
      getNextAvailableId in interface ComponentUtil
      Parameters:
      baseName - like ess, meter without a number
      startingNumber - the number at the end of the id to start from
      componentIds - the used componentIds from the other apps, because if the user updates multiple instances very quickly and components of the same type are created they are not instantly added to the componentManager
      Returns:
      the id
    • getPreferredRelays

      public String[] getPreferredRelays(List<String> ignoreIds, int[] relays4Channel, int[] relays8Channel)
      Description copied from interface: ComponentUtil
      Gets the preferred relays. If the default ports are are already taken the next available in a row are taken. If not enough in a row are available the first available relays of any relayboard are returned.
      Specified by:
      getPreferredRelays in interface ComponentUtil
      Parameters:
      ignoreIds - the ids of the components that should be ignored
      relays4Channel - the default ports on a 4-Channel Relay
      relays8Channel - the default ports on a 8-Channel Relay
      Returns:
      the relays
    • updateInterfaces

      public void updateInterfaces(User user, List<NetworkInterface<?>> interfaces) throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentUtil
      updates the interfaces in the Host configuration.
      Specified by:
      updateInterfaces in interface ComponentUtil
      Parameters:
      user - the executing user
      interfaces - the new interfaces
      Throws:
      OpenemsError.OpenemsNamedException - on error
    • updateScheduler

      public void updateScheduler(User user, List<String> schedulerExecutionOrder, List<EdgeConfig.Component> components) throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentUtil
      updates the execution order of the scheduler only adds or changes order of the given id s.
      Specified by:
      updateScheduler in interface ComponentUtil
      Parameters:
      user - the executing user
      schedulerExecutionOrder - the execution order
      components - the components which are currently created
      Throws:
      OpenemsError.OpenemsNamedException - when the scheduler can not be updated
    • removeIdsInSchedulerIfExisting

      public void removeIdsInSchedulerIfExisting(User user, List<String> removedIds) throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentUtil
      removes the given id s from the scheduler if they exist in the scheduler.
      Specified by:
      removeIdsInSchedulerIfExisting in interface ComponentUtil
      Parameters:
      user - the executing user
      removedIds - the ip s that should be removed
      Throws:
      OpenemsError.OpenemsNamedException - on error
    • getSchedulerIds

      public List<String> getSchedulerIds() throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentUtil
      Gets the current id's in the scheduler.
      Specified by:
      getSchedulerIds in interface ComponentUtil
      Returns:
      the id's
      Throws:
      OpenemsError.OpenemsNamedException - on error
    • getScheduler

      Description copied from interface: ComponentUtil
      Gets the scheduler Component.
      Specified by:
      getScheduler in interface ComponentUtil
      Returns:
      the scheduler component
      Throws:
      OpenemsError.OpenemsNamedException - if more or no scheduler is available
    • removeIdsWhichNotExist

      public List<String> removeIdsWhichNotExist(List<String> ids, List<EdgeConfig.Component> components)
      Description copied from interface: ComponentUtil
      Creates a new List with only components which exist in the current configuration or in the passed components list.
      Specified by:
      removeIdsWhichNotExist in interface ComponentUtil
      Parameters:
      ids - the initial list
      components - the current creating components
      Returns:
      a new list only with id's of components that exist
    • insertSchedulerOrder

      public List<String> insertSchedulerOrder(List<String> actualOrder, List<String> insertOrder)
      Description copied from interface: ComponentUtil
      Inserts the insertOrder into the actual Order.
      Specified by:
      insertSchedulerOrder in interface ComponentUtil
      Parameters:
      actualOrder - the current scheduler order
      insertOrder - the order which should be inserted
      Returns:
      the complete order
    • updateHosts

      public void updateHosts(User user, List<InterfaceConfiguration> ips, List<InterfaceConfiguration> oldIps) throws OpenemsError.OpenemsNamedException
      Description copied from interface: ComponentUtil
      updates the host configuration deletes ip s that are in oldIps but not in ips and adds ip s that are in ips but not in oldIps.
      Specified by:
      updateHosts in interface ComponentUtil
      Parameters:
      user - the executing user
      ips - the ip s that should be in the configuration
      oldIps - the old ip s that were in the old configuration
      Throws:
      OpenemsError.OpenemsNamedException - on error
    • getComponent

      public Optional<EdgeConfig.Component> getComponent(String id, String factoryId)
      Description copied from interface: ComponentUtil
      Specified by:
      getComponent in interface ComponentUtil
      Parameters:
      id - the id of the component
      factoryId - the factoryId of the component
      Returns:
      the optional component