@Test public void testMergesHDandSDforFilms() { BtVodEntry btVodEntrySD = filmRow("About Alex"); btVodEntrySD.setProductTargetBandwidth("SD"); BtVodEntry btVodEntryHD = filmRow("About Alex - HD"); btVodEntryHD.setGuid(PRODUCT_GUID + "_HD"); btVodEntryHD.setProductTargetBandwidth("HD"); when(imageExtractor.imagesFor(Matchers.<BtVodEntry>any())).thenReturn(ImmutableSet.<Image>of()); when(btVodBrandProvider.brandRefFor(btVodEntrySD)).thenReturn(Optional.<ParentRef>absent()); when(btVodBrandProvider.brandRefFor(btVodEntryHD)).thenReturn(Optional.<ParentRef>absent()); when(seriesProvider.seriesFor(btVodEntryHD)).thenReturn(Optional.<Series>absent()); when(seriesProvider.seriesFor(btVodEntrySD)).thenReturn(Optional.<Series>absent()); itemExtractor.process(btVodEntrySD); itemExtractor.process(btVodEntryHD); Item writtenItem = Iterables.getOnlyElement(itemExtractor.getProcessedItems().values()); assertThat(writtenItem.getTitle(), is("About Alex")); assertThat(writtenItem.getDescription(), is(SYNOPSIS)); assertThat(writtenItem.getVersions().size(), is(2)); Version hdVersion = Iterables.get(writtenItem.getVersions(), 0); Version sdVersion = Iterables.get(writtenItem.getVersions(), 1); assertThat( Iterables.getOnlyElement(sdVersion.getManifestedAs()).getHighDefinition(), is(false)); assertThat(Iterables.getOnlyElement(hdVersion.getManifestedAs()).getHighDefinition(), is(true)); }
public Optional<String> beanValue(String pattern) { if (fieldvalue.isPresent()) return fieldvalue; try { if (bean == null) return Optional.absent(); Object o = PropertyUtils.getProperty(bean, this.fieldname); PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(bean, this.fieldname); Class c = pd.getPropertyType(); if (c == String.class) { } else if (c == Integer.class || c == int.class) { } else if (c == Long.class || c == long.class) { } else if (c == Float.class || c == float.class) { } else if (c == Boolean.class || c == boolean.class) { } else if (c == Date.class) { } else if (Enum.class.isAssignableFrom(c)) { } return Optional.of((String) o); } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } return Optional.absent(); }
@Test public void testMergesImagesAndDescriptionsForHDAndSD() { BtVodEntry btVodEntrySD = filmRow("About Alex"); btVodEntrySD.setProductTargetBandwidth("SD"); btVodEntrySD.setDescription("sd"); btVodEntrySD.setProductLongDescription("sdLong"); BtVodEntry btVodEntryHD = filmRow("About Alex - HD"); btVodEntryHD.setGuid(PRODUCT_GUID + "_HD"); btVodEntryHD.setProductTargetBandwidth("HD"); btVodEntryHD.setDescription("hd"); btVodEntryHD.setProductLongDescription("hdLong"); Image sdImage = new Image("sdImage"); Image hdImage = new Image("hdImage"); when(imageExtractor.imagesFor(btVodEntrySD)).thenReturn(ImmutableSet.of(sdImage)); when(imageExtractor.imagesFor(btVodEntryHD)).thenReturn(ImmutableSet.of(hdImage)); when(btVodBrandProvider.brandRefFor(btVodEntrySD)).thenReturn(Optional.<ParentRef>absent()); when(btVodBrandProvider.brandRefFor(btVodEntryHD)).thenReturn(Optional.<ParentRef>absent()); when(seriesProvider.seriesFor(btVodEntryHD)).thenReturn(Optional.<Series>absent()); when(seriesProvider.seriesFor(btVodEntrySD)).thenReturn(Optional.<Series>absent()); itemExtractor.process(btVodEntrySD); itemExtractor.process(btVodEntryHD); Item item = Iterables.get(itemExtractor.getProcessedItems().values(), 0); verify(descriptionAndImageUpdater) .updateDescriptionsAndImages( eq(item), eq(btVodEntryHD), eq(ImmutableSet.of(hdImage)), anySet()); }
public Optional<Employee> authenticate(String accessTokenId) throws AuthenticationException { // Check input, must be a valid UUID UUID accessTokenUUID; try { accessTokenUUID = UUID.fromString(accessTokenId); } catch (IllegalArgumentException e) { return Optional.absent(); } // Get the access token from the database Optional<AccessToken> accessToken = accessTokenDAO.findAccessTokenById(accessTokenUUID); if (accessToken == null || !accessToken.isPresent()) { return Optional.absent(); } // Check if the last access time is not too far in the past (the access token is expired) Period period = new Period(accessToken.get().getLastAccessUTC(), new DateTime()); if (period.getMinutes() > ACCESS_TOKEN_EXPIRE_TIME_MIN) { return Optional.absent(); } // Update the access time for the token accessTokenDAO.setLastAccessTime(accessTokenUUID, new DateTime()); // Return the user's id for processing return Optional.of(accessToken.get().getEmployee()); }
@Override public void setUpMessageQueue() { messageEvents.clear(); // Standard client will start as attached // Cipher key success (first unlock) final MessageEvent event1 = new MessageEvent( MessageEventType.CIPHERED_KEY_VALUE, Optional.<HardwareWalletMessage>of(MessageEventFixtures.newCipheredKeyValue()), Optional.<Message>absent()); messageEvents.add(event1); // Cipher key success (second unlock after restore) final MessageEvent event2 = new MessageEvent( MessageEventType.CIPHERED_KEY_VALUE, Optional.<HardwareWalletMessage>of(MessageEventFixtures.newCipheredKeyValue()), Optional.<Message>absent()); messageEvents.add(event2); }
@Test public void testHttp() throws Exception { // Verify that http_proxy and HTTP_PROXY are used for http requests assertExpectedProxyConfig( proxyConfigFromEnv( "http", ImmutableMap.of( "http_proxy", PROXY_URL, "HTTP_PROXY", "http://ignore", "https_proxy", "http://ignore", "HTTPS_PROXY", "http://ignore")) .get()); assertExpectedProxyConfig( proxyConfigFromEnv( "http", ImmutableMap.of( "HTTP_PROXY", PROXY_URL, "https_proxy", "http://ignore", "HTTPS_PROXY", "http://ignore")) .get()); // Verify that https_proxy and HTTPS_PROXY are not used for http requests assertThat( proxyConfigFromEnv( "http", ImmutableMap.of("https_proxy", PROXY_URL, "HTTPS_PROXY", "http://ignore")), is(Optional.absent())); assertThat( proxyConfigFromEnv("http", ImmutableMap.of("HTTPS_PROXY", PROXY_URL)), is(Optional.absent())); }
@Test public void succeedsToListAll() throws Throwable { int virtualNetworkNumber = 2; List<VirtualSubnet> expectedVirtualSubnets = new ArrayList<>(); for (int i = 0; i < virtualNetworkNumber; ++i) { VirtualSubnet expectedVirtualSubnet = new VirtualSubnet(); expectedVirtualSubnet.setId(UUID.randomUUID().toString()); expectedVirtualSubnet.setName("virtualNetwork" + i); expectedVirtualSubnets.add(expectedVirtualSubnet); } when(frontendClient.list(projectId, Project.KIND, Optional.absent(), Optional.of(1))) .thenReturn(new ResourceList<>(expectedVirtualSubnets)); Response response = listNetworks(Optional.absent(), Optional.of(1), Optional.absent()); assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); ResourceList<VirtualSubnet> virtualNetworks = response.readEntity(new GenericType<ResourceList<VirtualSubnet>>() {}); assertThat(virtualNetworks.getItems().size(), is(virtualNetworkNumber)); for (int i = 0; i < virtualNetworkNumber; ++i) { VirtualSubnet expectedVirtualSubnet = expectedVirtualSubnets.get(i); VirtualSubnet actualVirtualSubnet = virtualNetworks.getItems().get(i); assertThat(actualVirtualSubnet, is(expectedVirtualSubnet)); String apiRoutePath = UriBuilder.fromPath(SubnetResourceRoutes.SUBNET_PATH) .build(expectedVirtualSubnet.getId()) .toString(); assertThat(actualVirtualSubnet.getSelfLink().endsWith(apiRoutePath), is(true)); assertThat(new URI(actualVirtualSubnet.getSelfLink()).isAbsolute(), is(true)); } }
private List<SingularityRequestParent> getRequestsWithDeployState( Iterable<SingularityRequestWithState> requests) { List<String> requestIds = Lists.newArrayList(); for (SingularityRequestWithState requestWithState : requests) { requestIds.add(requestWithState.getRequest().getId()); } List<SingularityRequestParent> parents = Lists.newArrayListWithCapacity(requestIds.size()); Map<String, SingularityRequestDeployState> deployStates = deployManager.getRequestDeployStatesByRequestIds(requestIds); for (SingularityRequestWithState requestWithState : requests) { Optional<SingularityRequestDeployState> deployState = Optional.fromNullable(deployStates.get(requestWithState.getRequest().getId())); parents.add( new SingularityRequestParent( requestWithState.getRequest(), requestWithState.getState(), deployState, Optional.<SingularityDeploy>absent(), Optional.<SingularityDeploy>absent(), Optional.<SingularityPendingDeploy>absent())); } return parents; }
/** * @param e The payment protocol exception (either an ERROR or a DOWN) * @return A suitable payment session summary */ public static PaymentSessionSummary newPaymentSessionFromException(Exception e, String hostName) { log.warn("Failed payment server: Host={} Failure={}", hostName, e.getMessage()); // Default handling is ERROR if (e instanceof InterruptedException) { return new PaymentSessionSummary( Optional.<PaymentSession>absent(), null, PaymentSessionStatus.DOWN, RAGStatus.AMBER, CoreMessageKey.PAYMENT_SESSION_DOWN, new String[] {hostName, e.getMessage()}); } if (e instanceof TimeoutException) { return new PaymentSessionSummary( Optional.<PaymentSession>absent(), null, PaymentSessionStatus.DOWN, RAGStatus.AMBER, CoreMessageKey.PAYMENT_SESSION_DOWN, new String[] {hostName, e.getMessage()}); } // Use default response return new PaymentSessionSummary( Optional.<PaymentSession>absent(), null, PaymentSessionStatus.ERROR, RAGStatus.AMBER, CoreMessageKey.PAYMENT_SESSION_ERROR, new String[] {hostName, e.getMessage()}); }
@Test public void sanitizeSymlinkedWorkingDirectory() throws IOException { TemporaryFolder folder = new TemporaryFolder(); folder.create(); // Setup up a symlink to our working directory. Path symlinkedRoot = folder.getRoot().toPath().resolve("symlinked-root"); java.nio.file.Files.createSymbolicLink(symlinkedRoot, tmp.getRootPath()); // Run the build, setting PWD to the above symlink. Typically, this causes compilers to use // the symlinked directory, even though it's not the right project root. Map<String, String> envCopy = Maps.newHashMap(System.getenv()); envCopy.put("PWD", symlinkedRoot.toString()); workspace .runBuckCommandWithEnvironmentAndContext( tmp.getRootPath(), Optional.<NGContext>absent(), Optional.<BuckEventListener>absent(), Optional.of(ImmutableMap.copyOf(envCopy)), "build", "//:simple#default,static") .assertSuccess(); // Verify that we still sanitized this path correctly. Path lib = workspace.getPath("buck-out/gen/simple#default,static/libsimple.a"); String contents = Files.asByteSource(lib.toFile()).asCharSource(Charsets.ISO_8859_1).read(); assertFalse(lib.toString(), contents.contains(tmp.getRootPath().toString())); assertFalse(lib.toString(), contents.contains(symlinkedRoot.toString())); folder.delete(); }
@Test public void failsToListAllWithException() throws Throwable { when(frontendClient.list(projectId, Project.KIND, Optional.absent(), Optional.of(1))) .thenThrow(new ExternalException("failed")); assertThat( listNetworks(Optional.absent(), Optional.of(1), Optional.absent()).getStatus(), is(500)); }
@Value.Lazy public Optional<AbstractDeclaring> okTypeAdaptersProvider() { Optional<DeclaringType> typeDefining = declaringType().isPresent() ? Optional.of(declaringType().get().associatedTopLevel()) : Optional.<DeclaringType>absent(); Optional<OkTypeAdaptersMirror> typeDefined = typeDefining.isPresent() ? typeDefining.get().okTypeAdapters() : Optional.<OkTypeAdaptersMirror>absent(); Optional<OkTypeAdaptersMirror> packageDefined = packageOf().okTypeAdapters(); if (packageDefined.isPresent()) { if (typeDefined.isPresent()) { report() .withElement(typeDefining.get().element()) .annotationNamed(OkTypeAdaptersMirror.simpleName()) .warning( "@%s is also used on the package, this type level annotation is ignored", OkTypeAdaptersMirror.simpleName()); } return Optional.<AbstractDeclaring>of(packageOf()); } return typeDefined.isPresent() ? Optional.<AbstractDeclaring>of(typeDefining.get()) : Optional.<AbstractDeclaring>absent(); }
/** * Returns an {@link Optional} containing the last element in this fluent iterable. If the * iterable is empty, {@code Optional.absent()} is returned. * * @throws NullPointerException if the last element is null; if this is a possibility, use {@link * Iterables#getLast} instead. */ public final Optional<E> last() { // Iterables#getLast was inlined here so we don't have to throw/catch a NSEE // TODO(kevinb): Support a concurrently modified collection? if (iterable instanceof List) { List<E> list = (List<E>) iterable; if (list.isEmpty()) { return Optional.absent(); } return Optional.of(list.get(list.size() - 1)); } Iterator<E> iterator = iterable.iterator(); if (!iterator.hasNext()) { return Optional.absent(); } /* * TODO(kevinb): consider whether this "optimization" is worthwhile. Users * with SortedSets tend to know they are SortedSets and probably would not * call this method. */ if (iterable instanceof SortedSet) { SortedSet<E> sortedSet = (SortedSet<E>) iterable; return Optional.of(sortedSet.last()); } while (true) { E current = iterator.next(); if (!iterator.hasNext()) { return Optional.of(current); } } }
private String getGoEnvFromTool(ProcessExecutor processExecutor, String env) { Path goTool = getGoToolPath(); Optional<Map<String, String>> goRootEnv = delegate .getPath("go", "root") .transform( new Function<Path, Map<String, String>>() { @Override public Map<String, String> apply(Path input) { return ImmutableMap.of("GOROOT", input.toString()); } }); try { ProcessExecutor.Result goToolResult = processExecutor.launchAndExecute( ProcessExecutorParams.builder() .addCommand(goTool.toString(), "env", env) .setEnvironment(goRootEnv) .build(), EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_ERR), /* stdin */ Optional.<String>absent(), /* timeOutMs */ Optional.<Long>absent(), /* timeoutHandler */ Optional.<Function<Process, Void>>absent()); if (goToolResult.getExitCode() == 0) { return CharMatcher.WHITESPACE.trimFrom(goToolResult.getStdout().get()); } else { throw new HumanReadableException(goToolResult.getStderr().get()); } } catch (InterruptedException e) { throw Throwables.propagate(e); } catch (IOException e) { throw new HumanReadableException(e, "Could not run \"%s env %s\": %s", env, goTool); } }
@GET @Path("/{id}/log/size") public long getLogSize(@PathParam("id") long id) { Optional<ModuleBuild> build = get(id); if (!build.isPresent()) { throw new NotFoundException("No build found for ID " + id); } Optional<String> taskId = build.get().getBuild().getTaskId(); if (!taskId.isPresent()) { throw new NotFoundException("No taskId found for build ID " + id); } String path = taskId.get() + "/service.log"; Optional<Long> absent = Optional.absent(); Optional<String> grep = Optional.absent(); Optional<MesosFileChunkObject> chunk = singularityClient.readSandBoxFile(taskId.get(), path, grep, absent, absent); if (chunk.isPresent()) { return chunk.get().getOffset(); } else { Collection<SingularityS3Log> s3Logs = singularityClient.getTaskLogs(taskId.get()); if (s3Logs.isEmpty()) { throw new NotFoundException("No S3 log found for ID " + id); } else if (s3Logs.size() > 1) { throw new NotFoundException("Multiple S3 logs found for ID " + id); } SingularityS3Log s3Log = s3Logs.iterator().next(); return s3Log.getSize(); } }
@Test public void testTaskAssigned() { expectAnyMaintenanceCalls(); expectOfferDeclineIn(10); IScheduledTask task = makeTask("a", PENDING); TaskInfo mesosTask = makeTaskInfo(task); Capture<Runnable> timeoutCapture = expectTaskGroupBackoff(10); expect(assigner.maybeAssign(OFFER_A, task)).andReturn(Optional.<TaskInfo>absent()); expect(preemptor.findPreemptionSlotFor("a")).andReturn(Optional.<String>absent()); Capture<Runnable> timeoutCapture2 = expectTaskGroupBackoff(10, 20); expect(assigner.maybeAssign(OFFER_A, task)).andReturn(Optional.of(mesosTask)); driver.launchTask(OFFER_A.getId(), mesosTask); Capture<Runnable> timeoutCapture3 = expectTaskGroupBackoff(10); expectTaskGroupBackoff(10, 20); expect(preemptor.findPreemptionSlotFor("b")).andReturn(Optional.<String>absent()); replayAndCreateScheduler(); offerQueue.addOffer(OFFER_A); changeState(task, INIT, PENDING); timeoutCapture.getValue().run(); timeoutCapture2.getValue().run(); // Ensure the offer was consumed. changeState(makeTask("b"), INIT, PENDING); timeoutCapture3.getValue().run(); }
@Test public void testTaskDeleted() { expectAnyMaintenanceCalls(); expectOfferDeclineIn(10); final IScheduledTask task = makeTask("a", PENDING); Capture<Runnable> timeoutCapture = expectTaskGroupBackoff(10); expect(assigner.maybeAssign(OFFER_A, task)).andReturn(Optional.<TaskInfo>absent()); expectTaskGroupBackoff(10, 20); expect(preemptor.findPreemptionSlotFor("a")).andReturn(Optional.<String>absent()); replayAndCreateScheduler(); offerQueue.addOffer(OFFER_A); changeState(task, INIT, PENDING); timeoutCapture.getValue().run(); // Ensure the offer was consumed. changeState(task, INIT, PENDING); storage.write( new MutateWork.NoResult.Quiet() { @Override protected void execute(MutableStoreProvider storeProvider) { storeProvider.getUnsafeTaskStore().deleteTasks(Tasks.ids(task)); } }); taskGroups.tasksDeleted(new TasksDeleted(ImmutableSet.of(task))); timeoutCapture.getValue().run(); }
public static class Builder { private Optional<Calendar> startDate = Optional.absent(); private Optional<Calendar> endDate = Optional.absent(); private Optional<String> Vendor = Optional.absent(); private Optional<Integer> poId = Optional.absent(); private Builder() {} public Builder startDate(Calendar startDate) { this.startDate = Optional.of(startDate); return this; } public Builder endDate(Calendar endDate) { this.endDate = Optional.of(endDate); return this; } public Builder Vendor(String Vendor) { this.Vendor = Optional.of(Vendor); return this; } public Builder poId(Integer poId2) { this.poId = Optional.of(poId2); return this; } public VarianceReportFilter create() { return new VarianceReportFilter(startDate, endDate, Vendor, poId); } }
private Optional<RuleKey> calculateDepFileRuleKey( BuildRule rule, Optional<ImmutableList<String>> depFile, boolean allowMissingInputs) throws IOException { Preconditions.checkState(useDependencyFileRuleKey(rule)); // Extract the dep file from the last build. If we don't find one, abort. if (!depFile.isPresent()) { return Optional.absent(); } // Add in the inputs explicitly listed in the dep file. If any inputs are no longer on disk, // this means something changed and a dep-file based rule key can't be calculated. ImmutableList<Path> inputs = FluentIterable.from(depFile.get()).transform(MorePaths.TO_PATH).toList(); RuleKeyBuilder builder = depFileRuleKeyBuilderFactory.newInstance(rule); for (Path input : inputs) { try { builder.setPath(input); } catch (NoSuchFileException e) { if (!allowMissingInputs) { throw e; } return Optional.absent(); } } return Optional.of(builder.build()); }
@Test public final void shouldCreateCorrectOrderDates3() { // given Entity order = mockOrder(START_DATE_1.toDate(), null, null, END_DATE_1.toDate(), null, null); // when Optional<OrderDates> maybeOrderDates = OrderDates.of(order); // then Assert.assertTrue(maybeOrderDates.isPresent()); OrderDates orderDates = maybeOrderDates.get(); Assert.assertEquals(START_DATE_1, orderDates.getStart().planned()); Assert.assertEquals(Optional.<LocalDate>absent(), orderDates.getStart().corrected()); Assert.assertEquals(Optional.<LocalDate>absent(), orderDates.getStart().effective()); Assert.assertEquals(START_DATE_1, orderDates.getStart().correctedWithFallback()); Assert.assertEquals(START_DATE_1, orderDates.getStart().effectiveWithFallback()); Assert.assertEquals(END_DATE_1, orderDates.getEnd().planned()); Assert.assertEquals(Optional.<LocalDate>absent(), orderDates.getEnd().corrected()); Assert.assertEquals(Optional.<LocalDate>absent(), orderDates.getEnd().effective()); Assert.assertEquals(END_DATE_1, orderDates.getEnd().correctedWithFallback()); Assert.assertEquals(END_DATE_1, orderDates.getEnd().effectiveWithFallback()); }
@Value.Lazy public Optional<RepositoryMirror> repository() { if (!declaringType().isPresent()) { return Optional.absent(); } Optional<RepositoryMirror> repositoryMirror = kind().isIncluded() || kind().isDefinedValue() ? declaringType().get().repository() : Optional.<RepositoryMirror>absent(); if (repositoryMirror.isPresent() && !typeAdaptersProvider().isPresent()) { if (kind().isNested()) { report() .annotationNamed(RepositoryMirror.simpleName()) .error( "@Mongo.%s should also have associated @Gson.%s on a top level type.", RepositoryMirror.simpleName(), TypeAdaptersMirror.simpleName()); } else { report() .annotationNamed(RepositoryMirror.simpleName()) .warning( "@Mongo.%s types better have explicit @Gson.%s annotation" + " be placed on the class or enclosing package." + " It is also common to forget to generate type adapters" + " for nested document classes, which will fallback to reflective Gson adapter otherwise.", RepositoryMirror.simpleName(), TypeAdaptersMirror.simpleName()); } } return repositoryMirror; }
@Test public void succeedsToListAllWithPageLink() throws Throwable { String pageLink = "randomPageLink"; VirtualSubnet expectedVirtualSubnet = new VirtualSubnet(); expectedVirtualSubnet.setId(UUID.randomUUID().toString()); expectedVirtualSubnet.setName("virtualNetwork"); when(frontendClient.nextList(pageLink)) .thenReturn(new ResourceList<>(ImmutableList.of(expectedVirtualSubnet))); Response response = listNetworks(Optional.absent(), Optional.absent(), Optional.of(pageLink)); assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode())); ResourceList<VirtualSubnet> virtualNetworks = response.readEntity(new GenericType<ResourceList<VirtualSubnet>>() {}); assertThat(virtualNetworks.getItems().size(), is(1)); VirtualSubnet actualVirtualSubnet = virtualNetworks.getItems().get(0); assertThat(actualVirtualSubnet, is(expectedVirtualSubnet)); String apiRoutePath = UriBuilder.fromPath(SubnetResourceRoutes.SUBNET_PATH) .build(expectedVirtualSubnet.getId()) .toString(); assertThat(actualVirtualSubnet.getSelfLink().endsWith(apiRoutePath), is(true)); assertThat(new URI(actualVirtualSubnet.getSelfLink()).isAbsolute(), is(true)); }
public YarnService( Config config, String applicationName, String applicationId, YarnConfiguration yarnConfiguration, FileSystem fs, EventBus eventBus) throws Exception { this.applicationName = applicationName; this.applicationId = applicationId; this.config = config; this.eventBus = eventBus; this.gobblinMetrics = config.getBoolean(ConfigurationKeys.METRICS_ENABLED_KEY) ? Optional.of(buildGobblinMetrics()) : Optional.<GobblinMetrics>absent(); this.eventSubmitter = config.getBoolean(ConfigurationKeys.METRICS_ENABLED_KEY) ? Optional.of(buildEventSubmitter()) : Optional.<EventSubmitter>absent(); this.yarnConfiguration = yarnConfiguration; this.fs = fs; this.amrmClientAsync = closer.register( AMRMClientAsync.createAMRMClientAsync(1000, new AMRMClientCallbackHandler())); this.amrmClientAsync.init(this.yarnConfiguration); this.nmClientAsync = closer.register(NMClientAsync.createNMClientAsync(new NMClientCallbackHandler())); this.nmClientAsync.init(this.yarnConfiguration); this.initialContainers = config.getInt(GobblinYarnConfigurationKeys.INITIAL_CONTAINERS_KEY); this.requestedContainerMemoryMbs = config.getInt(GobblinYarnConfigurationKeys.CONTAINER_MEMORY_MBS_KEY); this.requestedContainerCores = config.getInt(GobblinYarnConfigurationKeys.CONTAINER_CORES_KEY); this.containerHostAffinityEnabled = config.getBoolean(GobblinYarnConfigurationKeys.CONTAINER_HOST_AFFINITY_ENABLED); this.helixInstanceMaxRetries = config.getInt(GobblinYarnConfigurationKeys.HELIX_INSTANCE_MAX_RETRIES); this.containerJvmArgs = config.hasPath(GobblinYarnConfigurationKeys.CONTAINER_JVM_ARGS_KEY) ? Optional.of(config.getString(GobblinYarnConfigurationKeys.CONTAINER_JVM_ARGS_KEY)) : Optional.<String>absent(); this.containerLaunchExecutor = Executors.newFixedThreadPool( 10, ExecutorsUtils.newThreadFactory( Optional.of(LOGGER), Optional.of("ContainerLaunchExecutor"))); this.tokens = getSecurityTokens(); }
@Test public void testNoProxyVar() throws Exception { assertThat(proxyConfigFromEnv("http", ImmutableMap.of()), is(Optional.absent())); assertThat(proxyConfigFromEnv("https", ImmutableMap.of()), is(Optional.absent())); assertThat(proxyConfigFromEnv("http", ImmutableMap.of("foo", "bar")), is(Optional.absent())); assertThat(proxyConfigFromEnv("https", ImmutableMap.of("foo", "bar")), is(Optional.absent())); }
public ProcessResult runBuckCommand(Path repoRoot, String... args) throws IOException { return runBuckCommandWithEnvironmentAndContext( repoRoot, Optional.<NGContext>absent(), Optional.<BuckEventListener>absent(), Optional.<ImmutableMap<String, String>>absent(), args); }
@Override public Optional<ContentHierarchyAndSummaries> process( ProgData progData, Channel channel, DateTimeZone zone, Timestamp updatedAt) { try { log.trace("Channel: {} ProgData: {} UpdatedAt: {}", channel, progData, updatedAt); if (shouldNotProcess(progData)) { return Optional.absent(); } Optional<Brand> possibleBrand = getBrand(progData, channel, updatedAt); Brand brandSummary = null; if (possibleBrand.isPresent() && hasBrandSummary(progData)) { brandSummary = getBrandSummary(progData, possibleBrand.get(), updatedAt); } Optional<Series> possibleSeries = getSeries(progData, channel, updatedAt); Series seriesSummary = null; if (possibleSeries.isPresent() && hasSeriesSummary(progData)) { seriesSummary = getSeriesSummary(progData, possibleSeries.get(), updatedAt); } boolean isEpisode = possibleBrand.isPresent() || possibleSeries.isPresent(); ItemAndBroadcast itemAndBroadcast = isClosedBrand(possibleBrand) ? getClosedEpisode(progData, channel, zone, updatedAt) : getFilmOrEpisode(progData, channel, zone, isEpisode, updatedAt); Item item = itemAndBroadcast.getItem(); // TODO: there is an unknown bug preventing this from working (MBST-17174) if (!isEpisode) { item.setParentRef(null); } item.setGenericDescription(isGenericDescription(progData)); item.addAlias(PaHelper.getProgIdAlias(progData.getProgId())); item.setLastUpdated(updatedAt.toDateTimeUTC()); return Optional.of( new ContentHierarchyAndSummaries( possibleBrand, possibleSeries, item, itemAndBroadcast.getBroadcast().requireValue(), Optional.fromNullable(brandSummary), Optional.fromNullable(seriesSummary))); } catch (Exception e) { log.error("Failed to process PA programme data", e); adapterLog.record( new AdapterLogEntry(Severity.ERROR) .withCause(e) .withSource(PaProgrammeProcessor.class) .withDescription(e.getMessage())); } return Optional.absent(); }
@Override public void onThrowable(Throwable t) { LOG.trace("Exception while making health check for task {}", task.getTaskId(), t); saveResult( Optional.<Integer>absent(), Optional.<String>absent(), Optional.of(String.format("Healthcheck failed due to exception: %s", t.getMessage()))); }
@Test public void test_getLastSegment() throws Exception { assertThat(getLastSegment(HTTP_URI), equalTo(Optional.<String>absent())); assertThat(getLastSegment(HTTP_WITH_PATH_URI), equalTo(Optional.of("here"))); assertThat(getLastSegment(HTTPS_URI), equalTo(Optional.<String>absent())); assertThat(getLastSegment(FILE_ABS_URI), equalTo(Optional.of("asd"))); assertThat(getLastSegment(FILE_REL_URI), equalTo(Optional.of("qweasd"))); }
public Optional<Double> currentBestBound() { if (!this.basicLpSolver.getObjSense().isPresent()) { return Optional.absent(); } if (nodeStack.isEmpty()) { return Optional.absent(); } return nodeStack.peek().getBestBound(); }
/** * Add a link to this resource * * @param href The target href for the link, relative to the href of this resource. * @param rel * @return */ public MutableResource withLink(String href, String rel, Predicate<ReadableResource> predicate) { withLink( href, rel, Optional.of(predicate), Optional.<String>absent(), Optional.<String>absent(), Optional.<String>absent()); return this; }