Codota Logo
TenantAware.runAsTenant
Code IndexAdd Codota to your IDE (free)

How to use
runAsTenant
method
in
org.eclipse.hawkbit.tenancy.TenantAware

Best Java code snippets using org.eclipse.hawkbit.tenancy.TenantAware.runAsTenant (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Dictionary d =
  • Codota Iconnew Hashtable()
  • Codota IconBundle bundle;bundle.getHeaders()
  • Codota Iconnew Properties()
  • Smart code suggestions by Codota
}
origin: org.eclipse.hawkbit/hawkbit-repository-jpa

@Override
public <E extends TenantAwareBaseEntity> E findEntity(final String tenant, final Long id,
    final Class<E> entityType) {
  return tenantAware.runAsTenant(tenant, () -> entityManager.find(entityType, id));
}
origin: eclipse/hawkbit

@Override
public <E extends TenantAwareBaseEntity> E findEntity(final String tenant, final Long id,
    final Class<E> entityType) {
  return tenantAware.runAsTenant(tenant, () -> entityManager.find(entityType, id));
}
origin: eclipse/hawkbit

@Override
public boolean isEnable(final DmfTenantSecurityToken secruityToken) {
  return tenantAware.runAsTenant(secruityToken.getTenant(), configurationKeyTenantRunner);
}
origin: eclipse/hawkbit

@Override
public Object getPreAuthenticatedCredentials(final DmfTenantSecurityToken secruityToken) {
  final String authorityNameConfigurationValue = tenantAware.runAsTenant(secruityToken.getTenant(),
      sslIssuerNameConfigTenantRunner);
  String controllerId = secruityToken.getControllerId();
  // in case of legacy download artifact, the controller ID is not in the
  // URL path, so then we just use the common name header
  if (controllerId == null || "anonymous".equals(controllerId)) {
    controllerId = secruityToken.getHeader(caCommonNameHeader);
  }
  final List<String> knownHashes = splitMultiHashBySemicolon(authorityNameConfigurationValue);
  final String cntlId = controllerId;
  return knownHashes.stream().map(hashItem -> new HeaderAuthentication(cntlId, hashItem))
      .collect(Collectors.toSet());
}
origin: eclipse/hawkbit

try {
  LOG.debug("entering system code execution");
  return tenantAware.runAsTenant(tenant, () -> {
    try {
      setSystemContext(SecurityContextHolder.getContext());
origin: eclipse/hawkbit

/**
 * Flush the update queue by means to persisting
 * {@link Target#getLastTargetQuery()}.
 */
private void flushUpdateQueue() {
  LOG.debug("Run flushUpdateQueue.");
  final int size = queue.size();
  if (size <= 0) {
    return;
  }
  LOG.debug("{} events in flushUpdateQueue.", size);
  final Set<TargetPoll> events = Sets.newHashSetWithExpectedSize(queue.size());
  final int drained = queue.drainTo(events);
  if (drained <= 0) {
    return;
  }
  try {
    events.stream().collect(Collectors.groupingBy(TargetPoll::getTenant)).forEach((tenant, polls) -> {
      final TransactionCallback<Void> createTransaction = status -> updateLastTargetQueries(tenant, polls);
      tenantAware.runAsTenant(tenant,
          () -> DeploymentHelper.runInNewTransaction(txManager, "flushUpdateQueue", createTransaction));
    });
  } catch (final RuntimeException ex) {
    LOG.error("Failed to persist UpdateQueue content.", ex);
    return;
  }
  LOG.debug("{} events persisted.", drained);
}
origin: org.eclipse.hawkbit/hawkbit-repository-jpa

/**
 * Flush the update queue by means to persisting
 * {@link Target#getLastTargetQuery()}.
 */
private void flushUpdateQueue() {
  LOG.debug("Run flushUpdateQueue.");
  final int size = queue.size();
  if (size <= 0) {
    return;
  }
  LOG.debug("{} events in flushUpdateQueue.", size);
  final Set<TargetPoll> events = Sets.newHashSetWithExpectedSize(queue.size());
  final int drained = queue.drainTo(events);
  if (drained <= 0) {
    return;
  }
  try {
    events.stream().collect(Collectors.groupingBy(TargetPoll::getTenant)).forEach((tenant, polls) -> {
      final TransactionCallback<Void> createTransaction = status -> updateLastTargetQueries(tenant, polls);
      tenantAware.runAsTenant(tenant, () -> runInNewTransaction("flushUpdateQueue", createTransaction));
    });
  } catch (final RuntimeException ex) {
    LOG.error("Failed to persist UpdateQueue content.", ex);
    return;
  }
  LOG.debug("{} events persisted.", drained);
}
origin: eclipse/hawkbit

@EventListener(classes = RolloutGroupDeletedEvent.class)
void invalidateCachedTotalTargetCountOnRolloutGroupDelete(final RolloutGroupDeletedEvent event) {
  final Cache cache = tenantAware.runAsTenant(event.getTenant(), () -> cacheManager.getCache(CACHE_GR_NAME));
  cache.evict(event.getEntityId());
}
origin: eclipse/hawkbit

@Override
public HeaderAuthentication getPreAuthenticatedCredentials(final DmfTenantSecurityToken secruityToken) {
  final String gatewayToken = tenantAware.runAsTenant(secruityToken.getTenant(),
      gatewaySecurityTokenKeyConfigRunner);
  return new HeaderAuthentication(secruityToken.getControllerId(), gatewayToken);
}
origin: eclipse/hawkbit

@EventListener(classes = RolloutDeletedEvent.class)
void invalidateCachedTotalTargetCountOnRolloutDelete(final RolloutDeletedEvent event) {
  final Cache cache = tenantAware.runAsTenant(event.getTenant(), () -> cacheManager.getCache(CACHE_RO_NAME));
  cache.evict(event.getEntityId());
}
origin: eclipse/hawkbit

@Override
public HeaderAuthentication getPreAuthenticatedPrincipal(final DmfTenantSecurityToken secruityToken) {
  // retrieve the common name header and the authority name header from
  // the http request and combine them together
  final String commonNameValue = secruityToken.getHeader(caCommonNameHeader);
  final String knownSslIssuerConfigurationValue = tenantAware.runAsTenant(secruityToken.getTenant(),
      sslIssuerNameConfigTenantRunner);
  final String sslIssuerHashValue = getIssuerHashHeader(secruityToken, knownSslIssuerConfigurationValue);
  if (commonNameValue != null && LOGGER.isTraceEnabled()) {
    LOGGER.trace("Found commonNameHeader {}={}, using as credentials", caCommonNameHeader, commonNameValue);
  }
  if (sslIssuerHashValue != null && LOGGER.isTraceEnabled()) {
    LOGGER.trace("Found sslIssuerHash ****, using as credentials for tenant {}", secruityToken.getTenant());
  }
  if (commonNameValue != null && sslIssuerHashValue != null) {
    return new HeaderAuthentication(commonNameValue, sslIssuerHashValue);
  }
  return null;
}
origin: org.eclipse.hawkbit/hawkbit-repository-jpa

  @Override
  @Transactional(propagation = Propagation.NOT_SUPPORTED)
  public void forEachTenant(final Consumer<String> consumer) {

    Page<String> tenants;
    Pageable query = new PageRequest(0, MAX_TENANTS_QUERY);
    do {
      tenants = findTenants(query);
      tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
        try {
          consumer.accept(tenant);
        } catch (final RuntimeException ex) {
          LOGGER.error("Exception on forEachTenant execution for tenant {}. Continue with next tenant.",
              tenant, ex);
        }
        return null;
      }));
    } while (tenants.hasNext() && (query = tenants.nextPageable()) != null);

  }
}
origin: org.eclipse.hawkbit/hawkbit-repository-jpa

private void usageStatsPerTenant(final SystemUsageReportWithTenants report) {
  final List<String> tenants = findTenants(new PageRequest(0, MAX_TENANTS_QUERY)).getContent();
  tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
    report.addTenantData(systemStatsManagement.getStatsOfTenant());
    return null;
  }));
}
origin: eclipse/hawkbit

  @Override
  @Transactional(propagation = Propagation.NOT_SUPPORTED)
  // Exception squid:S2229 - calling findTenants without transaction is
  // intended in this case
  @SuppressWarnings("squid:S2229")
  public void forEachTenant(final Consumer<String> consumer) {

    Page<String> tenants;
    Pageable query = PageRequest.of(0, MAX_TENANTS_QUERY);
    do {
      tenants = findTenants(query);
      tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
        try {
          consumer.accept(tenant);
        } catch (final RuntimeException ex) {
          LOGGER.error("Exception on forEachTenant execution for tenant {}. Continue with next tenant.",
              tenant, ex);
        }
        return null;
      }));
    } while (tenants.hasNext() && (query = tenants.nextPageable()) != null);

  }
}
origin: eclipse/hawkbit

private void usageStatsPerTenant(final SystemUsageReportWithTenants report) {
  final List<String> tenants = findTenants(PageRequest.of(0, MAX_TENANTS_QUERY)).getContent();
  tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
    report.addTenantData(systemStatsManagement.getStatsOfTenant());
    return null;
  }));
}
origin: eclipse/hawkbit

@EventListener(classes = AbstractActionEvent.class)
void invalidateCachedTotalTargetCountActionStatus(final AbstractActionEvent event) {
  if (event.getRolloutId() != null) {
    final Cache cache = tenantAware.runAsTenant(event.getTenant(), () -> cacheManager.getCache(CACHE_RO_NAME));
    cache.evict(event.getRolloutId());
  }
  if (event.getRolloutGroupId() != null) {
    final Cache cache = tenantAware.runAsTenant(event.getTenant(), () -> cacheManager.getCache(CACHE_GR_NAME));
    cache.evict(event.getRolloutGroupId());
  }
}
origin: org.eclipse.hawkbit/hawkbit-autoconfigure

/**
 * Was overridden that not every event has to run within a own
 * tenantAware.
 */
@Override
public void multicastEvent(final ApplicationEvent event, final ResolvableType eventType) {
  if (applicationEventFilter.filter(event)) {
    return;
  }
  if (serviceMatcher == null || !(event instanceof RemoteTenantAwareEvent)) {
    super.multicastEvent(event, eventType);
    return;
  }
  final RemoteTenantAwareEvent remoteEvent = (RemoteTenantAwareEvent) event;
  if (serviceMatcher.isFromSelf(remoteEvent)) {
    super.multicastEvent(event, eventType);
    return;
  }
  tenantAware.runAsTenant(remoteEvent.getTenant(), () -> {
    super.multicastEvent(event, eventType);
    return null;
  });
}
origin: eclipse/hawkbit

/**
 * Was overridden that not every event has to run within a own
 * tenantAware.
 */
@Override
public void multicastEvent(final ApplicationEvent event, final ResolvableType eventType) {
  if (applicationEventFilter.filter(event)) {
    return;
  }
  if (serviceMatcher == null || !(event instanceof RemoteTenantAwareEvent)) {
    super.multicastEvent(event, eventType);
    return;
  }
  final RemoteTenantAwareEvent remoteEvent = (RemoteTenantAwareEvent) event;
  if (serviceMatcher.isFromSelf(remoteEvent)) {
    super.multicastEvent(event, eventType);
    return;
  }
  tenantAware.runAsTenant(remoteEvent.getTenant(), () -> {
    super.multicastEvent(event, eventType);
    return null;
  });
}
origin: eclipse/hawkbit

@Override
@Transactional
@Retryable(include = {
    ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteTenant(final String t) {
  final String tenant = t.toUpperCase();
  cacheManager.evictCaches(tenant);
  rolloutStatusCache.evictCaches(tenant);
  tenantAware.runAsTenant(tenant, () -> {
    entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant);
    tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
    tenantConfigurationRepository.deleteByTenant(tenant);
    targetRepository.deleteByTenant(tenant);
    targetFilterQueryRepository.deleteByTenant(tenant);
    rolloutRepository.deleteByTenant(tenant);
    targetTagRepository.deleteByTenant(tenant);
    distributionSetTagRepository.deleteByTenant(tenant);
    distributionSetRepository.deleteByTenant(tenant);
    distributionSetTypeRepository.deleteByTenant(tenant);
    softwareModuleRepository.deleteByTenant(tenant);
    artifactRepository.deleteByTenant(tenant);
    softwareModuleTypeRepository.deleteByTenant(tenant);
    return null;
  });
}
origin: org.eclipse.hawkbit/hawkbit-repository-jpa

@Override
@Transactional
@Retryable(include = {
    ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteTenant(final String t) {
  final String tenant = t.toUpperCase();
  cacheManager.evictCaches(tenant);
  rolloutStatusCache.evictCaches(tenant);
  tenantAware.runAsTenant(tenant, () -> {
    entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant);
    tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant);
    tenantConfigurationRepository.deleteByTenant(tenant);
    targetRepository.deleteByTenant(tenant);
    targetFilterQueryRepository.deleteByTenant(tenant);
    rolloutRepository.deleteByTenant(tenant);
    targetTagRepository.deleteByTenant(tenant);
    distributionSetTagRepository.deleteByTenant(tenant);
    distributionSetRepository.deleteByTenant(tenant);
    distributionSetTypeRepository.deleteByTenant(tenant);
    softwareModuleRepository.deleteByTenant(tenant);
    artifactRepository.deleteByTenant(tenant);
    softwareModuleTypeRepository.deleteByTenant(tenant);
    return null;
  });
}
org.eclipse.hawkbit.tenancyTenantAwarerunAsTenant

Javadoc

Gives the possibility to run a certain code under a specific given tenant. Only the given TenantRunner is executed under the specific tenant e.g. under control of an ThreadLocal. After the TenantRunner it must be ensured that the original tenant before this invocation is reset.

Popular methods of TenantAware

  • getCurrentTenant
    Implementation might retrieve the current tenant from a session or thread-local.

Popular in Java

  • Creating JSON documents from java classes using gson
  • onRequestPermissionsResult (Fragment)
  • runOnUiThread (Activity)
  • putExtra (Intent)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • URLConnection (java.net)
    The abstract class URLConnection is the superclass of all classes that represent a communications li
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • PriorityQueue (java.util)
    An unbounded priority Queue based on a priority heap. The elements of the priority queue are ordered
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now