Search in sources :

Example 51 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project killbill by killbill.

the class SubscriptionUsageInArrear method computeInArrearUsageInterval.

@VisibleForTesting
List<ContiguousIntervalUsageInArrear> computeInArrearUsageInterval() {
    final List<ContiguousIntervalUsageInArrear> usageIntervals = Lists.newLinkedList();
    final Map<String, ContiguousIntervalUsageInArrear> inFlightInArrearUsageIntervals = new HashMap<String, ContiguousIntervalUsageInArrear>();
    final Set<String> allSeenUsage = new HashSet<String>();
    for (final BillingEvent event : subscriptionBillingEvents) {
        // Extract all in arrear /consumable usage section for that billing event.
        final List<Usage> usages = findUsageInArrearUsages(event);
        allSeenUsage.addAll(Collections2.transform(usages, new Function<Usage, String>() {

            @Override
            public String apply(final Usage input) {
                return input.getName();
            }
        }));
        // All inflight usage interval are candidates to be closed unless we see that current billing event referencing the same usage section.
        final Set<String> toBeClosed = new HashSet<String>(allSeenUsage);
        for (final Usage usage : usages) {
            // Add inflight usage interval if non existent
            ContiguousIntervalUsageInArrear existingInterval = inFlightInArrearUsageIntervals.get(usage.getName());
            if (existingInterval == null) {
                existingInterval = new ContiguousIntervalUsageInArrear(usage, accountId, invoiceId, rawSubscriptionUsage, targetDate, rawUsageStartDate, internalTenantContext);
                inFlightInArrearUsageIntervals.put(usage.getName(), existingInterval);
            }
            // Add billing event for that usage interval
            existingInterval.addBillingEvent(event);
            // Remove usage interval for toBeClosed set
            toBeClosed.remove(usage.getName());
        }
        // Build the usage interval that are no longer referenced
        for (final String usageName : toBeClosed) {
            final ContiguousIntervalUsageInArrear interval = inFlightInArrearUsageIntervals.remove(usageName);
            if (interval != null) {
                interval.addBillingEvent(event);
                usageIntervals.add(interval.build(true));
            }
        }
    }
    for (final String usageName : inFlightInArrearUsageIntervals.keySet()) {
        usageIntervals.add(inFlightInArrearUsageIntervals.get(usageName).build(false));
    }
    inFlightInArrearUsageIntervals.clear();
    return usageIntervals;
}
Also used : Function(com.google.common.base.Function) Usage(org.killbill.billing.catalog.api.Usage) RawUsage(org.killbill.billing.usage.RawUsage) HashMap(java.util.HashMap) BillingEvent(org.killbill.billing.junction.BillingEvent) HashSet(java.util.HashSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 52 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project killbill by killbill.

the class IncompletePaymentTransactionTask method getNextNotificationTime.

@VisibleForTesting
DateTime getNextNotificationTime(final Integer attemptNumber, final InternalTenantContext tenantContext) {
    final List<TimeSpan> retries = paymentConfig.getIncompleteTransactionsRetries(tenantContext);
    if (attemptNumber > retries.size()) {
        return null;
    }
    final TimeSpan nextDelay = retries.get(attemptNumber - 1);
    return clock.getUTCNow().plusMillis((int) nextDelay.getMillis());
}
Also used : TimeSpan(org.skife.config.TimeSpan) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 53 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class AMLauncher method setupTokens.

@Private
@VisibleForTesting
protected void setupTokens(ContainerLaunchContext container, ContainerId containerID) throws IOException {
    Map<String, String> environment = container.getEnvironment();
    environment.put(ApplicationConstants.APPLICATION_WEB_PROXY_BASE_ENV, application.getWebProxyBase());
    // Set AppSubmitTime to be consumable by the AM.
    ApplicationId applicationId = application.getAppAttemptId().getApplicationId();
    environment.put(ApplicationConstants.APP_SUBMIT_TIME_ENV, String.valueOf(rmContext.getRMApps().get(applicationId).getSubmitTime()));
    Credentials credentials = new Credentials();
    DataInputByteBuffer dibb = new DataInputByteBuffer();
    ByteBuffer tokens = container.getTokens();
    if (tokens != null) {
        // TODO: Don't do this kind of checks everywhere.
        dibb.reset(tokens);
        credentials.readTokenStorageStream(dibb);
        tokens.rewind();
    }
    // Add AMRMToken
    Token<AMRMTokenIdentifier> amrmToken = createAndSetAMRMToken();
    if (amrmToken != null) {
        credentials.addToken(amrmToken.getService(), amrmToken);
    }
    DataOutputBuffer dob = new DataOutputBuffer();
    credentials.writeTokenStorageToStream(dob);
    container.setTokens(ByteBuffer.wrap(dob.getData(), 0, dob.getLength()));
}
Also used : AMRMTokenIdentifier(org.apache.hadoop.yarn.security.AMRMTokenIdentifier) DataInputByteBuffer(org.apache.hadoop.io.DataInputByteBuffer) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ByteBuffer(java.nio.ByteBuffer) DataInputByteBuffer(org.apache.hadoop.io.DataInputByteBuffer) Credentials(org.apache.hadoop.security.Credentials) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Private(org.apache.hadoop.classification.InterfaceAudience.Private)

Example 54 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class LeveldbRMStateStore method loadRMAppAttemptState.

@VisibleForTesting
ApplicationAttemptStateData loadRMAppAttemptState(ApplicationAttemptId attemptId) throws IOException {
    String attemptKey = getApplicationAttemptNodeKey(attemptId);
    byte[] data = null;
    try {
        data = db.get(bytes(attemptKey));
    } catch (DBException e) {
        throw new IOException(e);
    }
    if (data == null) {
        return null;
    }
    return createAttemptState(attemptId.toString(), data);
}
Also used : DBException(org.iq80.leveldb.DBException) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 55 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class LeveldbRMStateStore method loadRMAppState.

@VisibleForTesting
ApplicationStateData loadRMAppState(ApplicationId appId) throws IOException {
    String appKey = getApplicationNodeKey(appId);
    byte[] data = null;
    try {
        data = db.get(bytes(appKey));
    } catch (DBException e) {
        throw new IOException(e);
    }
    if (data == null) {
        return null;
    }
    return createApplicationState(appId.toString(), data);
}
Also used : DBException(org.iq80.leveldb.DBException) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1955 IOException (java.io.IOException)284 ArrayList (java.util.ArrayList)214 Map (java.util.Map)156 HashMap (java.util.HashMap)147 List (java.util.List)113 File (java.io.File)94 ImmutableMap (com.google.common.collect.ImmutableMap)72 HashSet (java.util.HashSet)67 Path (org.apache.hadoop.fs.Path)63 ImmutableList (com.google.common.collect.ImmutableList)60 Path (java.nio.file.Path)60 Set (java.util.Set)52 Matcher (java.util.regex.Matcher)46 Collectors (java.util.stream.Collectors)46 Collection (java.util.Collection)39 Optional (java.util.Optional)38 NotNull (org.jetbrains.annotations.NotNull)37 ImmutableSet (com.google.common.collect.ImmutableSet)34 TreeMap (java.util.TreeMap)34