/** * Returns a String containing the string representation of all elements from * the given collection, separated by the separator string. * * @param collection The collection * @param sep The separator string * @return A string: elem(0) + sep + ... + elem(N) */ public static String mkString(Collection<?> collection, String sep) { return mkString(collection, "", sep, ""); }
private static List<GenericTarget> defaultTargets(Collection<SearchChain> allSearchChains) { Collection<Provider> providers = CollectionUtil.filter(allSearchChains, Provider.class); List<GenericTarget> defaultTargets = new ArrayList<>(); for (Provider provider : providers) { defaultTargets.addAll(provider.defaultFederationTargets()); } return defaultTargets; } }
static AccessLogTypeLiteral fromAttributeValue(String value) { return firstMatching( AccessLogTypeLiteral.values(), typeLiteral -> typeLiteral.attributeValue.equals(value)).get(); } }
private <T extends ConfigInstance> T getConfig(Class<T> configClass) { Subscriber subscriber = subscriberFactory.getSubscriber( Collections.singleton(new ConfigKey<>(configClass, configId))); try { subscriber.waitNextGeneration(); return configClass.cast(first(subscriber.config().values())); } finally { subscriber.close(); } }
/** * @return The set of all Cluster Controller service instances for the application. */ public static List<HostName> getClusterControllerInstancesInOrder(ApplicationInstance application, ClusterId contentClusterId) { Set<ServiceCluster> controllerClusters = getClusterControllerServiceClusters(application); Collection<ServiceCluster> controllerClustersForContentCluster = filter(controllerClusters, contentClusterId); Set<ServiceInstance> clusterControllerInstances; if (controllerClustersForContentCluster.size() == 1) { clusterControllerInstances = first(controllerClustersForContentCluster).serviceInstances(); } else if (controllerClusters.size() == 1) { ServiceCluster cluster = first(controllerClusters); log.warning("No cluster controller cluster for content cluster " + contentClusterId + ", using the only cluster controller cluster available: " + cluster.clusterId()); clusterControllerInstances = cluster.serviceInstances(); } else { throw new RuntimeException("Failed getting cluster controller for content cluster " + contentClusterId + ". Available clusters = " + controllerClusters + ", matching clusters = " + controllerClustersForContentCluster); } return clusterControllerInstances.stream() .sorted(CLUSTER_CONTROLLER_INDEX_COMPARATOR) .map(serviceInstance -> serviceInstance.hostName()) .collect(Collectors.toList()); }
@Override public BundleClasses getBundleClasses(ComponentSpecification bundleSpec, Set<String> packagesToScan) { //Temporary hack: Using class name since ClassLoaderOsgiFramework is not available at compile time in this bundle. if (osgiFramework.getClass().getName().equals("com.yahoo.application.container.impl.ClassLoaderOsgiFramework")) { Bundle syntheticClassPathBundle = first(osgiFramework.bundles()); ClassLoader classLoader = syntheticClassPathBundle.adapt(BundleWiring.class).getClassLoader(); return new BundleClasses( syntheticClassPathBundle, OsgiUtil.getClassEntriesForBundleUsingProjectClassPathMappings(classLoader, bundleSpec, packagesToScan)); } else { Bundle bundle = getBundle(bundleSpec); if (bundle == null) throw new RuntimeException("No bundle matching " + quote(bundleSpec)); return new BundleClasses(bundle, OsgiUtil.getClassEntriesInBundleClassPath(bundle, packagesToScan)); } }
public String getZooKeepersConnectionSpec() { return CollectionUtil.mkString(getZooKeepers(), ","); }
public Collection<LocalProvider> localProviders() { return CollectionUtil.filter(allChains().allComponents(), LocalProvider.class); }
private void watchPortChange() { Subscriber subscriber = subscriberFactory.getSubscriber(Collections.singleton(new ConfigKey<>(QrConfig.class, configId))); try { while (true) { subscriber.waitNextGeneration(); QrConfig newConfig = QrConfig.class.cast(first(subscriber.config().values())); if (qrConfig.rpc().port() != newConfig.rpc().port()) { com.yahoo.protect.Process.logAndDie( "Rpc port config has changed from " + qrConfig.rpc().port() + " to " + newConfig.rpc().port() + ". This we can not handle without a restart so we will just bail out."); } log.fine("Received new QrConfig :" + newConfig); } } finally { subscriber.close(); } }
/** * @param xmlLines XML with " replaced with ' */ public static Element parse(String... xmlLines) { List<String> lines = new ArrayList<>(); lines.add("<?xml version='1.0' encoding='utf-8' ?>"); lines.addAll(Arrays.asList(xmlLines)); try { return XmlHelper.getDocumentBuilder().parse( inputSource((CollectionUtil.mkString(lines, "\n").replace("'", "\"")))) .getDocumentElement(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public Result search(Query query, Execution execution) { Result mergedResults = execution.search(query); Results<SearchChainInvocationSpec, UnresolvedSearchChainException> targets = getTargets(query.getModel().getSources(), query.properties(), execution.context().getIndexFacts()); warnIfUnresolvedSearchChains(targets.errors(), mergedResults.hits()); Collection<SearchChainInvocationSpec> prunedTargets = pruneTargetsWithoutDocumentTypes(query.getModel().getRestrict(), targets.data()); Results<Target, ErrorMessage> regularTargetHandlers = resolveSearchChains(prunedTargets, execution.searchChainRegistry()); query.errors().addAll(regularTargetHandlers.errors()); Set<Target> targetHandlers = new LinkedHashSet<>(regularTargetHandlers.data()); targetHandlers.addAll(getAdditionalTargets(query, execution, targetSelector)); traceTargets(query, targetHandlers); if (targetHandlers.isEmpty()) return mergedResults; else if (targetHandlers.size() > 1) search(query, execution, targetHandlers, mergedResults); else if (shouldExecuteTargetLongerThanThread(query, targetHandlers.iterator().next())) search(query, execution, targetHandlers, mergedResults); // one target, but search in separate thread else search(query, execution, first(targetHandlers), mergedResults); // search in this thread return mergedResults; }
@Override public void validate(VespaModel model, DeployState deployState) { if (! deployState.isHosted()) return; if (! deployState.zone().environment().isProduction()) return; if (model.getAdmin().getApplicationType() != ApplicationType.DEFAULT) return; List<String> offendingClusters = new ArrayList<>(); for (ContainerCluster cluster : model.getContainerClusters().values()) { if (cluster.getHttp() == null || ! cluster.getHttp().getAccessControl().isPresent() || ! cluster.getHttp().getAccessControl().get().writeEnabled) if (hasHandlerThatNeedsProtection(cluster) || ! cluster.getAllServlets().isEmpty()) offendingClusters.add(cluster.getName()); } if (! offendingClusters.isEmpty()) throw new IllegalArgumentException( "Access-control must be enabled for write operations to container clusters in production zones: " + mkString(offendingClusters, "[", ", ", "].")); }
static Pair<VespaModel, Container> createContainerModel(Path applicationPath, FileRegistry fileRegistry, File preprocessedApplicationDir, Networking networkingOption, ConfigModelRepo configModelRepo) throws Exception { DeployLogger logger = new BaseDeployLogger(); FilesApplicationPackage rawApplicationPackage = new FilesApplicationPackage.Builder(applicationPath.toFile()) .includeSourceFiles(true).preprocessedDir(preprocessedApplicationDir).build(); ApplicationPackage applicationPackage = rawApplicationPackage.preprocess(getZone(), logger); validateApplication(applicationPackage); DeployState deployState = createDeployState(applicationPackage, fileRegistry, logger); VespaModel root = VespaModel.createIncomplete(deployState); ApplicationConfigProducerRoot vespaRoot = new ApplicationConfigProducerRoot(root, "vespa", deployState.getDocumentModel(), deployState.getVespaVersion(), deployState.getProperties().applicationId()); Element spec = containerRootElement(applicationPackage); ContainerModel containerModel = newContainerModelBuilder(networkingOption).build(deployState, root, configModelRepo, vespaRoot, spec); containerModel.getCluster().prepare(deployState); initializeContainerModel(containerModel, configModelRepo); Container container = first(containerModel.getCluster().getContainers()); // TODO: Separate out model finalization from the VespaModel constructor, // such that the above and below code to finalize the container can be // replaced by root.finalize(); initializeContainer(deployState.getDeployLogger(), container, spec); root.freezeModelTopology(); return new Pair<>(root, container); }