@Override public void activate() throws InterruptedException, CouldNotPerformException { super.activate(); MultiException.ExceptionStack exceptionStack = null; synchronized (unitMapLock) { for (AbstractUnitController unit : unitMap.values()) { try { unit.activate(); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } } MultiException.checkAndThrow("Could not activate all hosted units of " + this, exceptionStack); }
@Override public void update(Observable<UnitRegistryData> source, UnitRegistryData data) throws Exception { try { final UnitConfig newUnitConfig = Registries.getUnitRegistry(true).getUnitConfigById(getId()); if (!newUnitConfig.equals(getConfig())) { applyConfigUpdate(newUnitConfig); } } catch (NotAvailableException ex) { // unit config has been removed, probably because of deletion and a higher controller will do the shutdown in this case logger.debug("Could not update unit controller", ex); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not update unit config of " + this, ex, logger); } } };
@Override public void deactivate() throws InterruptedException, CouldNotPerformException { super.deactivate(); MultiException.ExceptionStack exceptionStack = null; synchronized (unitMapLock) { for (AbstractUnitController unit : unitMap.values()) { try { unit.deactivate(); } catch (CouldNotPerformException ex) { exceptionStack = MultiException.push(this, ex, exceptionStack); } } } MultiException.checkAndThrow("Could not deactivate all hosted units of " + this, exceptionStack); }
try (ClosableDataBuilder<DB> dataBuilder = getDataBuilder(this)) { DB internalBuilder = dataBuilder.getInternalBuilder(); if (hasOperationServiceForType(serviceType) && Services.hasServiceState(serviceType, ServiceTempus.REQUESTED, internalBuilder)) { actionDescription = actionDescription.toBuilder().setTransactionId(generateTransactionId()).build(); newState = newState.toBuilder().setField(descriptor, actionDescription).build(); applyDataUpdate(internalBuilder, serviceType); } catch (Exception ex) { throw new CouldNotPerformException("Could not apply service[" + serviceType.name() + "] update[" + value + "] for " + this + "!", ex);
unit.verifyAndUpdateAuthority(actionDescriptionBuilder.getActionAuthority(), actionFutureBuilder.getTicketAuthenticatorWrapperBuilder()); actionDescriptionBuilder.setTransactionId(unit.getTransactionIdByServiceType(actionDescriptionBuilder.getServiceStateDescription().getServiceType())); } catch (CouldNotPerformException ex) { if (ex.getCause() instanceof InterruptedException) { LOGGER.info("Update Allocation - Scope:[" + ScopeGenerator.generateStringRep(unit.getScope()) + "] State: [" + allocation.getState() + "]"); } catch (CouldNotPerformException ex) { LOGGER.info("Update Allocation - Scope[?] State[" + allocation.getState() + "]");
@Override public UnitTemplate.UnitType getUnitType() throws NotAvailableException { return getConfig().getType(); }
for (ServiceDescription serviceDescription : getUnitTemplate().getServiceDescriptionList()) { serviceInterfaceMap.put(StringProcessor.transformUpperCaseToCamelCase(serviceDescription.getType().name()) + StringProcessor.transformUpperCaseToCamelCase(serviceDescription.getPattern().name()), serviceDescription); ExceptionPrinter.printHistory(new CouldNotPerformException("Could not register Interface[" + serviceInterfaceClass + "] Method [" + serviceInterfaceMapEntry.getKey() + "] for Unit[" + this.getLabel() + "].", ex), logger);
protected <U extends AbstractUnitController<?, ?>> void registerUnit(final U unit) throws CouldNotPerformException { synchronized (unitMapLock) { try { if (unitMap.containsKey(unit.getId())) { throw new VerificationFailedException("Could not register " + unit + "! Unit with same name already registered!"); } unitMap.put(unit.getId(), unit); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not registerUnit!", ex); } } }
@Override public Future<ActionFuture> applyAction(final ActionDescription actionDescription) throws CouldNotPerformException, InterruptedException { try { if (!actionDescription.hasDescription() || actionDescription.getDescription().isEmpty()) { // Fallback print in case the description is not available. // Please make sure all action descriptions provide a description. logger.info("Action[" + actionDescription.getServiceStateDescription().getServiceType() + "] for unit[" + ScopeGenerator.generateStringRep(getScope()) + "] is without a description"); } else { logger.info(actionDescription.getDescription()); } logger.info("================"); final ActionImpl action = new ActionImpl(this); action.init(actionDescription); return action.execute(); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not apply action!", ex); } }
private void setRequestedState() throws CouldNotPerformException { try (ClosableDataBuilder dataBuilder = unit.getDataBuilder(this)) { // set the responsible action for the service attribute Message.Builder serviceStateBuilder = serviceAttribute.toBuilder(); Descriptors.FieldDescriptor fieldDescriptor = ProtoBufFieldProcessor.getFieldDescriptor(serviceStateBuilder, Service.RESPONSIBLE_ACTION_FIELD_NAME); serviceStateBuilder.setField(fieldDescriptor, actionDescriptionBuilder.build()); // set the updated service attribute as requested state in the unit data builder Services.invokeServiceMethod(serviceDescription.getType(), serviceDescription.getPattern(), ServiceTempus.REQUESTED, dataBuilder.getInternalBuilder(), serviceStateBuilder); } }
@Override public String getLabel() throws NotAvailableException { try { UnitConfig tmpConfig = getConfig(); if (!tmpConfig.hasLabel()) { throw new NotAvailableException("unitconfig.label"); } if (tmpConfig.getLabel().isEmpty()) { throw new InvalidStateException("unitconfig.label is empty"); } return getConfig().getLabel(); } catch (CouldNotPerformException ex) { throw new NotAvailableException("label", ex); } }
private void verifyActionDescription(final ActionDescription actionDescription) throws VerificationFailedException { try { if (actionDescription == null) { throw new NotAvailableException("ActionDescription"); } if (!actionDescription.hasServiceStateDescription()) { throw new NotAvailableException("ActionDescription.ServiceStateDescription"); } if (!actionDescription.getServiceStateDescription().hasUnitId() || actionDescription.getServiceStateDescription().getUnitId().isEmpty()) { throw new NotAvailableException("ActionDescription.ServiceStateDescription.UnitId"); } if (!actionDescription.getServiceStateDescription().getUnitId().equals(unit.getId())) { throw new InvalidStateException("Referred unit is not compatible with the registered unit controller!"); } } catch (CouldNotPerformException ex) { throw new VerificationFailedException("Given ActionDescription[" + actionDescription.getLabel() + "] is invalid!", ex); } }
public boolean isEnabled() { try { return getConfig().getEnablingState().getValue().equals(EnablingState.State.ENABLED); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); } return false; }
@Override public final String getId() throws NotAvailableException { try { UnitConfig tmpConfig = getConfig(); if (!tmpConfig.hasId()) { throw new NotAvailableException("unitconfig.id"); } if (tmpConfig.getId().isEmpty()) { throw new InvalidStateException("unitconfig.id is empty"); } return tmpConfig.getId(); } catch (CouldNotPerformException ex) { throw new NotAvailableException("id", ex); } }
if (getConfig().equals(config)) { logger.debug("Skip config update because no config change detected!"); return config;
Map<String, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder>> locations = Registries.getUnitRegistry().getLocationUnitConfigRemoteRegistry().getEntryMap(); if (!AuthorizationHelper.canAccess(getConfig(), null, null, locations)) { throw new PermissionDeniedException("You have no permission to execute this action."); Map<String, IdentifiableMessage<String, UnitConfig, UnitConfig.Builder>> locations = Registries.getUnitRegistry().getLocationUnitConfigRemoteRegistry().getEntryMap(); if (!AuthorizationHelper.canAccess(getConfig(), validatedTicketWrapper.getUserId(), groups, locations)) { throw new PermissionDeniedException("You have no permission to execute this action.");