if (sceneUnitConfig.getEnablingState().getValue() == EnablingStateType.EnablingState.State.ENABLED) { itemEntryList.add(new SceneItemEntry(sceneUnitConfig)); if (!unitConfig.getEnablingState().getValue().equals(EnablingStateType.EnablingState.State.ENABLED)) { continue; if (agentUnitConfig.getEnablingState().getValue() == EnablingState.State.ENABLED) { itemEntryList.add(new AgentItemEntry(agentUnitConfig, null)); if (appUnitConfig.getEnablingState().getValue() == EnablingState.State.ENABLED) { itemEntryList.add(new AppItemEntry(appUnitConfig));
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig deviceUnitConfig = entry.getMessage(); DeviceConfig deviceConfig = deviceUnitConfig.getDeviceConfig(); if (!oldInventoryStateMap.get(registry.isSandbox()).containsKey(deviceUnitConfig.getId())) { oldInventoryStateMap.get(registry.isSandbox()).put(deviceUnitConfig.getId(), deviceConfig.getInventoryState().getValue()); } if (!deviceConfig.hasInventoryState()) { throw new NotAvailableException("deviceConfig.inventoryState"); } if (!deviceConfig.getInventoryState().hasValue()) { throw new NotAvailableException("deviceConfig.inventoryState.value"); } if (deviceConfig.getInventoryState().getValue() != InventoryState.State.INSTALLED) { if (deviceUnitConfig.getEnablingState().getValue() == EnablingState.State.ENABLED) { EnablingState disabled = EnablingState.newBuilder().setValue(EnablingState.State.DISABLED).build(); throw new EntryModification(entry.setMessage(deviceUnitConfig.toBuilder().setEnablingState(disabled)), this); } } if (oldInventoryStateMap.get(registry.isSandbox()).get(deviceUnitConfig.getId()) != deviceConfig.getInventoryState().getValue()) { oldInventoryStateMap.get(registry.isSandbox()).put(deviceUnitConfig.getId(), deviceConfig.getInventoryState().getValue()); if (deviceConfig.getInventoryState().getValue() == InventoryState.State.INSTALLED) { EnablingState enabled = EnablingState.newBuilder().setValue(EnablingState.State.ENABLED).build(); throw new EntryModification(entry.setMessage(deviceUnitConfig.toBuilder().setEnablingState(enabled)), this); } } }
if (sourceUnitConfig.getEnablingState().getValue() != EnablingState.State.ENABLED) { throw new NotAvailableException("Source[" + ScopeGenerator.generateStringRep(sourceUnitConfig.getScope()) + "] is not enabled"); logger.debug("Found target id [" + unitId + "] with key [" + TARGET_KEY + "_" + i + "]"); UnitConfig targetUnitConfig = CachedUnitRegistryRemote.getRegistry().getUnitConfigById(unitId); if (targetUnitConfig.getEnablingState().getValue() != EnablingState.State.ENABLED) { logger.warn("TargetUnit[" + ScopeGenerator.generateStringRep(targetUnitConfig.getScope()) + "] " + "of powerStateSynchroniserAgent[" + ScopeGenerator.generateStringRep(config.getScope()) + "] is disabled and therefore skipped!");
if (!UnitConfigProcessor.isDalUnit(unitConfig) || unitConfig.getEnablingState().getValue() == State.DISABLED) { continue;
if (unitConfig.getEnablingState().getValue() == State.DISABLED) { disabledUnitRemoteMap.put(unitConfig.getId(), unitRemote); return;
this.unitConfigObserver = (source, data) -> { final UnitConfig unitConfig = (UnitConfig) data; if (unitRemoteMap.containsKey(unitConfig.getId()) && unitConfig.getEnablingState().getValue() == State.DISABLED) { unitRemoteTypeMap.get(superType).remove(unitRemote); } else if (disabledUnitRemoteMap.containsKey(unitConfig.getId()) && unitConfig.getEnablingState().getValue() == State.ENABLED) {
if (unitConfigSource.getEnablingState().getValue() != State.ENABLED) { throw new InvalidStateException("Source Unit[" + unitConfigSource.getLabel() + ":" + unitConfigSource.getId() + "] is disbled and does not provide any transformation!"); if (unitConfigTarget.getEnablingState().getValue() != State.ENABLED) { throw new InvalidStateException("Target Unit[" + unitConfigTarget.getLabel() + ":" + unitConfigTarget.getId() + "] is disbled and does not provide any transformation!");
if (unitConfigSource.getEnablingState().getValue() != State.ENABLED) { return FutureProcessor.canceledFuture(new InvalidStateException("Source Unit[" + unitConfigSource.getLabel() + ":" + unitConfigSource.getId() + "] is disbled and does not provide any transformation!")); if (unitConfigTarget.getEnablingState().getValue() != State.ENABLED) { return FutureProcessor.canceledFuture(new InvalidStateException("Target Unit[" + unitConfigTarget.getLabel() + ":" + unitConfigTarget.getId() + "] is disbled and does not provide any transformation!"));
|| !deviceClassList.contains(config.getDeviceConfig().getDeviceClassId()) || config.getMetaConfig().getEntryList().stream().noneMatch(e -> "scope".equals(e.getKey())) || config.getEnablingState().getValue() != EnablingState.State.ENABLED) { if (!idRestriction.isEmpty()) { LOGGER.warn("Config of specified id " + config.getId() + " is not applicable for skeleton merging.");
@Override public void processData(String id, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder> entry, ProtoBufMessageMap<String, UnitConfig, UnitConfig.Builder> entryMap, ProtoBufRegistry<String, UnitConfig, UnitConfig.Builder> registry) throws CouldNotPerformException, EntryModification { UnitConfig dalUnitConfig = entry.getMessage(); // filter virtual units if(UnitConfigProcessor.isVirtualUnit(dalUnitConfig)) { return; } if (!dalUnitConfig.hasUnitHostId() || dalUnitConfig.getUnitHostId().isEmpty()) { throw new NotAvailableException("unitConfig.unitHostId"); } UnitConfig deviceUnitConfig = deviceRegistry.getMessage(dalUnitConfig.getUnitHostId()); if (!oldHostEnablingStateMap.get(registry.isSandbox()).containsKey(dalUnitConfig.getId())) { oldHostEnablingStateMap.get(registry.isSandbox()).put(dalUnitConfig.getId(), deviceUnitConfig.getEnablingState()); } if (oldHostEnablingStateMap.get(registry.isSandbox()).get(dalUnitConfig.getId()) != deviceUnitConfig.getEnablingState()) { oldHostEnablingStateMap.get(registry.isSandbox()).put(dalUnitConfig.getId(), deviceUnitConfig.getEnablingState()); if (deviceUnitConfig.getEnablingState().getValue() == EnablingState.State.ENABLED) { throw new EntryModification(entry.setMessage(dalUnitConfig.toBuilder().setEnablingState(deviceUnitConfig.getEnablingState())), this); } } if (deviceUnitConfig.getEnablingState().getValue() == EnablingState.State.DISABLED) { if (dalUnitConfig.getEnablingState().getValue() == EnablingState.State.ENABLED) { EnablingState disabled = EnablingState.newBuilder().setValue(EnablingState.State.DISABLED).build(); throw new EntryModification(entry.setMessage(dalUnitConfig.toBuilder().setEnablingState(disabled)), this); } } }
/** * Method establishes a connection to all enabled units. * The returned unit remote objects are fully synchronized with the unit controller and all states locally cached. * Use the {@code waitForData} flag to block the current thread until the unit remote is fully synchronized with the unit controller during the startup phase. * This synchronization is just done once and the current thread will not block if the unit remote was already synchronized before. * To force a resynchronization call {@link org.openbase.bco.dal.lib.layer.unit.UnitRemote#requestData()} on the remote instance. * Please avoid polling unit states! If you want to get informed about unit config or unit data state changes, please register new config or data observer on this remote instance. * <p> * Note: Please to not use this method if you not really need all units because this method establishes a connection to each unit and the synchronization will even continue if you are not working with the remote instances anymore. * * @param waitForData if this flag is set to true the current thread will block until the unit remote is fully synchronized with the unit controller. * @return a list of new or cached unit remotes which can be used to control the units or request all current unit states. * @throws NotAvailableException is thrown in case the unit is not available or the label is not unique enough to identify the unit. * @throws InterruptedException is thrown in case the thread is externally interrupted. */ public static List<UnitRemote<?>> getUnits(boolean waitForData) throws NotAvailableException, InterruptedException { try { final ArrayList<UnitRemote<?>> unitRemoteList = new ArrayList<>(); for (UnitConfig unitConfig : getUnitRegistry().getUnitConfigs()) { if (unitConfig.getEnablingState().getValue() != EnablingState.State.ENABLED) { continue; } unitRemoteList.add(getUnit(unitConfig, waitForData)); } return unitRemoteList; } catch (CouldNotPerformException ex) { throw new NotAvailableException("Units", ex); } }
private void registerUser() throws CouldNotPerformException, InterruptedException { for (UnitConfig unitConfig : unitRegistry.getUnitConfigs(UnitType.USER)) { if (unitConfig.getUserConfig().getUserName().equals(UserCreationPlugin.DEFAULT_ADMIN_USERNAME_AND_PASSWORD)) { admin = unitConfig; break; } } UserConfig.Builder config = UserConfig.newBuilder().setFirstName("Max").setLastName("Mustermann").setUserName(USER_NAME); UnitConfig.Builder userUnitConfig = UnitConfig.newBuilder().setType(UnitType.USER).setUserConfig(config).setEnablingState(EnablingState.newBuilder().setValue(EnablingState.State.ENABLED)); userUnitConfig.getPermissionConfigBuilder().getOtherPermissionBuilder().setWrite(true).setAccess(true).setRead(true); try { testUser = userRegisty.registerUserConfig(userUnitConfig.build()).get(); } catch (ExecutionException ex) { throw new CouldNotPerformException(ex); } }
/** * {@inheritDoc} * * @return {@inheritDoc} */ @Override public boolean isEnabled() { try { assert (getConfig() instanceof UnitConfig); return getConfig().getEnablingState().getValue().equals(EnablingState.State.ENABLED); } catch (CouldNotPerformException ex) { LoggerFactory.getLogger(org.openbase.bco.dal.lib.layer.unit.UnitRemote.class).warn("isEnabled() was called on non initialized unit!"); assert false; } return false; }
private void loadUnitRemotes(final List<UnitConfig> unitConfigs) throws InterruptedException, CouldNotPerformException { this.potentialRemotesNum = 0; this.successfullyRemotesNum = 0; this.failedRemotesNum = 0; final List<UnitConfig> unitConfigsBuf = new ArrayList<>(); for (final UnitConfig unitConfig : unitConfigs) { if (unitConfig.getType() != UnitType.DEVICE && unitConfig.getEnablingState().getValue() == State.ENABLED) { unitConfigsBuf.add(unitConfig); potentialRemotesNum++; } } LOGGER.info("Try to set state observation(s) of " + potentialRemotesNum + " potential unit remote(s)."); for (final UnitConfig unitConfig : unitConfigsBuf) { UNIT_REMOTE_OBSERVABLE.notifyObservers(unitConfig); } }
/** * Method returns the state source(s) result(s) (contains state value(s)) of the input enablingState. * * @param enablingState The EnablingState. * @return state source(s) result(s) of the input state. */ private List<RdfNodeObject> enablingStateSources(final EnablingState enablingState) { final List<RdfNodeObject> stateSources = new ArrayList<>(); final String enablingStateVal = enablingState.getValue().toString(); stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(enablingStateVal);}}, false)); return stateSources; }
@Override public boolean verifyConfig(UnitConfig config) throws VerificationFailedException { return config.getEnablingState().getValue() == EnablingState.State.ENABLED; } };
@Override public boolean verifyConfig(UnitConfig config) throws VerificationFailedException { return config.getEnablingState().getValue() == EnablingState.State.ENABLED; } };
@Override public boolean verifyConfig(UnitConfig config) throws VerificationFailedException { return config.getEnablingState().getValue() == EnablingState.State.ENABLED; } };