<commit_before>// (c) Copyright 2015 Cloudera, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.cloudera.director.spi.v2.provider;

import com.cloudera.director.spi.v2.model.Configured;
import com.cloudera.director.spi.v2.model.LocalizationContext;
import com.cloudera.director.spi.v2.model.Resource;
import com.cloudera.director.spi.v2.model.ResourceTemplate;
import com.cloudera.director.spi.v2.model.exception.PluginExceptionConditionAccumulator;

import java.util.Collection;
import java.util.Map;

/**
 * Represents a provider of cloud resources.
 *
 * @param <R> type of the resource created by this provider
 * @param <T> type of the template required by this provider to create a resource
 */
public interface ResourceProvider<R extends Resource<T>, T extends ResourceTemplate> {

  /**
   * Returns the resource provider metadata.
   *
   * @return the resource provider metadata
   */
  ResourceProviderMetadata getProviderMetadata();

  /**
   * Returns the type of resource managed by the provider.
   *
   * @return the type of resource managed by the provider
   */
  Resource.Type getResourceType();

  /**
   * Returns the localization context.
   *
   * @return the localization context
   */
  LocalizationContext getLocalizationContext();

  /**
   * Returns the resource template localization context.
   *
   * @return the resource template localization context
   */
  LocalizationContext getResourceTemplateLocalizationContext();

  /**
   * Validates the specified configuration, accumulating errors and warnings in the specified
   * accumulator.
   *
   * @param name the name of the template
   * @param configuration the configuration to be validated
   * @param accumulator   the exception condition accumulator
   */
  void validateResourceTemplateConfiguration(String name, Configured configuration,
      PluginExceptionConditionAccumulator accumulator);

  /**
   * Create a new resource template instance for this provider using the configuration.
   *
   * @param name          the name of the template
   * @param configuration the configuration
   * @param tags          tags to be added to the resource
   * @return a configured resource template
   */
  T createResourceTemplate(String name, Configured configuration, Map<String, String> tags);

  /**
   * Atomically allocates multiple resources with the specified identifiers based on a single
   * resource template. If not all the resources can be allocated, the number of resources
   * allocated must at least the specified minimum or the method must fail cleanly with no
   * billing implications.
   *
   * @param template    the resource template
   * @param resourceIds the unique identifiers for the resources
   * @param minCount    the minimum number of resources to allocate if not all resources can be
   *                    allocated
   * @return the successfully allocated resources. This is guaranteed to be equal to or greater
   * than <code>minCount</code> in size
   * @throws InterruptedException if the operation is interrupted
   */
  Collection<R> allocate(T template, Collection<String> resourceIds, int minCount)
      throws InterruptedException;

  /**
   * Returns current resource information for the specified resources, which are guaranteed to have
   * been created by this provider. This method takes resources, rather than resource identifiers,
   * so that any additional information associated with the resource, such as its template,<commit_msg>CLOUD-6963. No throw if allocated instance count < min<commit_after>// (c) Copyright 2015 Cloudera, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.cloudera.director.spi.v2.provider;

import com.cloudera.director.spi.v2.model.Configured;
import com.cloudera.director.spi.v2.model.LocalizationContext;
import com.cloudera.director.spi.v2.model.Resource;
import com.cloudera.director.spi.v2.model.ResourceTemplate;
import com.cloudera.director.spi.v2.model.exception.PluginExceptionConditionAccumulator;

import java.util.Collection;
import java.util.Map;

/**
 * Represents a provider of cloud resources.
 *
 * @param <R> type of the resource created by this provider
 * @param <T> type of the template required by this provider to create a resource
 */
public interface ResourceProvider<R extends Resource<T>, T extends ResourceTemplate> {

  /**
   * Returns the resource provider metadata.
   *
   * @return the resource provider metadata
   */
  ResourceProviderMetadata getProviderMetadata();

  /**
   * Returns the type of resource managed by the provider.
   *
   * @return the type of resource managed by the provider
   */
  Resource.Type getResourceType();

  /**
   * Returns the localization context.
   *
   * @return the localization context
   */
  LocalizationContext getLocalizationContext();

  /**
   * Returns the resource template localization context.
   *
   * @return the resource template localization context
   */
  LocalizationContext getResourceTemplateLocalizationContext();

  /**
   * Validates the specified configuration, accumulating errors and warnings in the specified
   * accumulator.
   *
   * @param name the name of the template
   * @param configuration the configuration to be validated
   * @param accumulator   the exception condition accumulator
   */
  void validateResourceTemplateConfiguration(String name, Configured configuration,
      PluginExceptionConditionAccumulator accumulator);

  /**
   * Create a new resource template instance for this provider using the configuration.
   *
   * @param name          the name of the template
   * @param configuration the configuration
   * @param tags          tags to be added to the resource
   * @return a configured resource template
   */
  T createResourceTemplate(String name, Configured configuration, Map<String, String> tags);

  /**
   * Atomically allocates multiple resources with the specified identifiers based on a single
   * resource template. More specifically, <p/>
   * if at least minCount resources can be allocated, the allocated amount of resources
   * will be returned.<p/>
   * if minCount resources cannot be allocated, no resource will be allocated with any billing
   * implications, returning an empty collection.
   *
   * @param template    the resource template
   * @param resourceIds the unique identifiers for the resources
   * @param minCount    the minimum number of resources to allocate if not all resources can be
   *                    allocated
   * @return the successfully allocated resources. If minCount can be satisfied, it will return a
   * collection with resources equal to or greater than <code>minCount</code> in size. Otherwise
   * it will return an empty collection
   * @throws InterruptedException if the operation is interrupted
   */
  Collection<R> allocate(T template, Collection<String> resourceIds, int minCount)
      throws InterruptedException;

  /**
   * Returns current resource information for the specified resources, which are guaranteed to have
   * been created by this provider. This method takes resources, rather than resource identifiers,
   * so that any additional information associated with the resource, such as its template,
{'fraction_non_alphanumeric': 0.06942590120160214, 'fraction_numerical': 0.0038839665007889307, 'mean_word_length': 3.7193585337915236, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3958497', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1978, 'n_words': 876}