Package io.openems.edge.core.appmanager
Class ComponentUtilImpl
java.lang.Object
io.openems.edge.core.appmanager.ComponentUtilImpl
- All Implemented Interfaces:
ComponentUtil
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.openems.edge.core.appmanager.ComponentUtil
ComponentUtil.PreferredRelay, ComponentUtil.RelayContactInfo, ComponentUtil.RelayInfo
-
Field Summary
Fields inherited from interface io.openems.edge.core.appmanager.ComponentUtil
CORE_COMPONENT_IDS
-
Constructor Summary
ConstructorsConstructorDescriptionComponentUtilImpl
(ComponentManager componentManager, org.osgi.service.cm.ConfigurationAdmin cm) -
Method Summary
Modifier and TypeMethodDescriptionboolean
anyComponentUses
(String value, List<String> ignoreIds) Checks if any component has the given String in its configuration.static boolean
equals
(com.google.gson.JsonElement expected, com.google.gson.JsonElement actual) Validates if the 'actual' matches the 'expected' value.static boolean
equals
(List<NetworkInterface<?>> interfaces, List<NetworkInterface<?>> otherInterfaces) Validates if the 'interfaces' matches the 'otherInterfaces'.getAllRelayInfos
(List<String> ignoreIds, Predicate<DigitalOutput> componentFilter, Function<DigitalOutput, String> componentAliasMapper, BiPredicate<DigitalOutput, BooleanWriteChannel> channelFilter, BiFunction<DigitalOutput, BooleanWriteChannel, String> channelAliasMapper, BiFunction<DigitalOutput, BooleanWriteChannel, List<String>> disabledReasons) Gets allRelayInfos
of allDigitalOutputs
.getComponent
(String id, String factoryId) Gets anOptional
of anEdgeConfig.Component
.getComponentByConfig
(EdgeConfig.Component component) Searches a component with the given component configuration.<T extends OpenemsComponent>
List<T>Gets the enabled Components with the starting id.<T extends OpenemsComponent>
List<T>getEnabledComponentsOfType
(Class<T> clazz) Gets the enabled Components of a Type.List<NetworkInterface<?>>
Gets the interfaces of the currently active network settings.static List<NetworkInterface<?>>
getInterfaces
(com.google.gson.JsonObject json) parses all interfaces from the given JsonObject.getNextAvailableId
(String baseName, int startingNumber, List<String> componentIds) Gets the next available id with the baseName starting with the given startingNumber.String[]
getPreferredRelays
(List<ComponentUtil.RelayInfo> relayInfos, int numberOfRelays, List<ComponentUtil.PreferredRelay> preferredRelaysDefinitions) Gets the preferred relays.Gets the scheduler Component.Gets the current id's in the scheduler.int[]
getUsedModbusUnitIds
(String modbusComponent) Gets an array of modbus unit ids which are already used by other components.insertSchedulerOrder
(List<String> actualOrder, List<String> insertOrder) Inserts the insertOrder into the actual Order.static boolean
isSameConfiguration
(List<String> errors, EdgeConfig.Component expectedComponent, EdgeConfig.Component actualComponent) Checks if the expectedComonents match with the actualComponent.static boolean
isSameConfigurationWithoutAlias
(List<String> errors, EdgeConfig.Component expectedComponent, EdgeConfig.Component actualComponent) Checks if the expectedComonents match with the actualComponent without checking the alias.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.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.static List<EdgeConfig.Component>
order
(List<EdgeConfig.Component> components) orders the list so components that need another component are coming after the needed component.void
removeIdsInSchedulerIfExisting
(User user, List<String> removedIds) removes the given id s from the scheduler if they exist in the scheduler.removeIdsWhichNotExist
(List<String> ids, List<EdgeConfig.Component> components) Creates a new List with only components which exist in the current configuration or in the passed components list.void
updateHosts
(User user, List<InterfaceConfiguration> ips, List<InterfaceConfiguration> oldIps) updates the host configuration deletes ip s that are inoldIps
but not inips
and adds ip s that are inips
but not inoldIps
.void
updateInterfaces
(User user, List<NetworkInterface<?>> interfaces) updates the interfaces in the Host configuration.void
updateScheduler
(User user, List<String> schedulerExecutionOrder, List<EdgeConfig.Component> components) updates the execution order of the scheduler only adds or changes order of the given id s.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.openems.edge.core.appmanager.ComponentUtil
getAllRelayInfos, getAllRelayInfos, getAllRelayInfos, getNextAvailableId
-
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 valueactual
- 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 interfacesotherInterfaces
- 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
Description copied from interface:ComponentUtil
Gets the interfaces of the currently active network settings.- Specified by:
getInterfaces
in interfaceComponentUtil
- 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 matchexpectedComponent
- the expected componentactualComponent
- 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 matchexpectedComponent
- the expected componentactualComponent
- 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 matchexpectedComponent
- the expected componentactualComponent
- 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 matchexpectedComponent
- the expected componentactualComponent
- the actual existing component- Returns:
- true if the configurations are the same
-
order
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
Description copied from interface:ComponentUtil
Checks if any component has the given String in its configuration.- Specified by:
anyComponentUses
in interfaceComponentUtil
- Parameters:
value
- that no component should haveignoreIds
- the id s of components which configuration should be ignored- Returns:
- true if a component has the given String in its configuration
-
getAllRelayInfos
public List<ComponentUtil.RelayInfo> getAllRelayInfos(List<String> ignoreIds, Predicate<DigitalOutput> componentFilter, Function<DigitalOutput, String> componentAliasMapper, BiPredicate<DigitalOutput, BooleanWriteChannel> channelFilter, BiFunction<DigitalOutput, BooleanWriteChannel, String> channelAliasMapper, BiFunction<DigitalOutput, BooleanWriteChannel, List<String>> disabledReasons) Description copied from interface:ComponentUtil
Gets allRelayInfos
of allDigitalOutputs
.- Specified by:
getAllRelayInfos
in interfaceComponentUtil
- Parameters:
ignoreIds
- the Component-IDs that should be ignored to check if they use any relaycomponentFilter
- aDigitalOutput
component filtercomponentAliasMapper
- aDigitalOutput
component alias mapperchannelFilter
- aDigitalOutput
channel filterchannelAliasMapper
- aDigitalOutput
channel alias mapperdisabledReasons
- aDigitalOutput
channel disabled function- Returns:
- a list of
RelayInfos
-
getComponentByConfig
Description copied from interface:ComponentUtil
Searches a component with the given component configuration.- Specified by:
getComponentByConfig
in interfaceComponentUtil
- Parameters:
component
- with the configuration to be searched for- Returns:
- the found component or null if not found
-
getEnabledComponentsOfStartingId
Description copied from interface:ComponentUtil
Gets the enabled Components with the starting id.- Specified by:
getEnabledComponentsOfStartingId
in interfaceComponentUtil
- 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
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 interfaceComponentUtil
- 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
Description copied from interface:ComponentUtil
Gets the next available id with the baseName starting with the given startingNumber.- Specified by:
getNextAvailableId
in interfaceComponentUtil
- Parameters:
baseName
- like ess, meter without a numberstartingNumber
- the number at the end of the id to start fromcomponentIds
- 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<ComponentUtil.RelayInfo> relayInfos, int numberOfRelays, List<ComponentUtil.PreferredRelay> preferredRelaysDefinitions) Description copied from interface:ComponentUtil
Gets the preferred relays. If the default ports 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 relay are returned.- Specified by:
getPreferredRelays
in interfaceComponentUtil
- Parameters:
relayInfos
- theRelayInfos
to search in for the preferred relaysnumberOfRelays
- the number of the result number of relayspreferredRelaysDefinitions
- theComponentUtil.PreferredRelay
options- Returns:
- the first found preferred 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 interfaceComponentUtil
- Parameters:
user
- the executing userinterfaces
- 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 interfaceComponentUtil
- Parameters:
user
- the executing userschedulerExecutionOrder
- the execution ordercomponents
- 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 interfaceComponentUtil
- Parameters:
user
- the executing userremovedIds
- the ip s that should be removed- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getSchedulerIds
Description copied from interface:ComponentUtil
Gets the current id's in the scheduler.- Specified by:
getSchedulerIds
in interfaceComponentUtil
- Returns:
- the id's
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getScheduler
Description copied from interface:ComponentUtil
Gets the scheduler Component.- Specified by:
getScheduler
in interfaceComponentUtil
- Returns:
- the scheduler component
- Throws:
OpenemsError.OpenemsNamedException
- if more or no scheduler is available
-
removeIdsWhichNotExist
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 interfaceComponentUtil
- Parameters:
ids
- the initial listcomponents
- the current creating components- Returns:
- a new list only with id's of components that exist
-
insertSchedulerOrder
Description copied from interface:ComponentUtil
Inserts the insertOrder into the actual Order.- Specified by:
insertSchedulerOrder
in interfaceComponentUtil
- Parameters:
actualOrder
- the current scheduler orderinsertOrder
- 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 inoldIps
but not inips
and adds ip s that are inips
but not inoldIps
.- Specified by:
updateHosts
in interfaceComponentUtil
- Parameters:
user
- the executing userips
- the ip s that should be in the configurationoldIps
- the old ip s that were in the old configuration- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getComponent
Description copied from interface:ComponentUtil
Gets anOptional
of anEdgeConfig.Component
.- Specified by:
getComponent
in interfaceComponentUtil
- Parameters:
id
- the id of the componentfactoryId
- the factoryId of the component- Returns:
- the optional component
-
getUsedModbusUnitIds
Description copied from interface:ComponentUtil
Gets an array of modbus unit ids which are already used by other components. The result of this method may not contain all modbus unit ids.- Specified by:
getUsedModbusUnitIds
in interfaceComponentUtil
- Parameters:
modbusComponent
- the id of the modbus component- Returns:
- an array of used modbus unit ids
-