Search in sources :

Example 1 with ProvisionerSystemContext

use of io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext in project cdap by caskdata.

the class AbstractDataprocProvisioner method getSystemContext.

/**
 * Returns the {@link ProvisionerSystemContext} that was passed to the {@link #initialize(ProvisionerSystemContext)}
 * method. The system properties will be reloaded via the {@link ProvisionerSystemContext#reloadProperties()}
 * method upon every time when this method is called.
 */
protected ProvisionerSystemContext getSystemContext() {
    ProvisionerSystemContext context = Objects.requireNonNull(systemContext, "System context is not available. Please make sure the initialize method has been called.");
    context.reloadProperties();
    return context;
}
Also used : ProvisionerSystemContext(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext)

Example 2 with ProvisionerSystemContext

use of io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext in project cdap by caskdata.

the class AbstractDataprocProvisioner method getSystemLabels.

/**
 * Returns a set of system labels that should be applied to all Dataproc entities.
 */
protected final Map<String, String> getSystemLabels() {
    Map<String, String> labels = new HashMap<>();
    ProvisionerSystemContext systemContext = getSystemContext();
    // dataproc only allows label values to be lowercase letters, numbers, or dashes
    labels.put(LABEL_VERSON, getVersionLabel());
    String extraLabelsStr = systemContext.getProperties().get(LABELS_PROPERTY);
    // name1=val1,name2=val2
    if (extraLabelsStr != null) {
        labels.putAll(DataprocUtils.parseLabels(extraLabelsStr));
    }
    return Collections.unmodifiableMap(labels);
}
Also used : ProvisionerSystemContext(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext) HashMap(java.util.HashMap)

Example 3 with ProvisionerSystemContext

use of io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext in project cdap by caskdata.

the class ProvisioningService method initializeProvisioners.

/**
 * Reloads provisioners in the extension directory. Any new provisioners will be added and any deleted provisioners
 * will be removed. Loaded provisioners will be initialized.
 */
private void initializeProvisioners() {
    Map<String, Provisioner> provisioners = provisionerProvider.loadProvisioners();
    Map<String, ProvisionerConfig> provisionerConfigs = provisionerConfigProvider.loadProvisionerConfigs(provisioners.values());
    LOG.debug("Provisioners = {}", provisioners);
    Map<String, ProvisionerDetail> details = new HashMap<>(provisioners.size());
    for (Map.Entry<String, Provisioner> provisionerEntry : provisioners.entrySet()) {
        String provisionerName = provisionerEntry.getKey();
        Provisioner provisioner = provisionerEntry.getValue();
        ProvisionerSystemContext provisionerSystemContext = new DefaultSystemProvisionerContext(cConf, provisionerName);
        try {
            provisioner.initialize(provisionerSystemContext);
        } catch (RuntimeException e) {
            LOG.warn("Error initializing the {} provisioner. It will not be available for use.", provisionerName, e);
            provisioners.remove(provisionerName);
            continue;
        }
        ProvisionerSpecification spec = provisioner.getSpec();
        ProvisionerConfig config = provisionerConfigs.getOrDefault(provisionerName, new ProvisionerConfig(new ArrayList<>(), null, null, false));
        details.put(provisionerName, new ProvisionerDetail(spec.getName(), spec.getLabel(), spec.getDescription(), config.getConfigurationGroups(), config.getFilters(), config.getIcon(), config.isBeta()));
    }
    provisionerInfo.set(new ProvisionerInfo(provisioners, details));
}
Also used : ProvisionerSystemContext(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext) ProvisionerSpecification(io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification) HashMap(java.util.HashMap) Provisioner(io.cdap.cdap.runtime.spi.provisioner.Provisioner) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ProvisionerDetail(io.cdap.cdap.proto.provisioner.ProvisionerDetail)

Aggregations

ProvisionerSystemContext (io.cdap.cdap.runtime.spi.provisioner.ProvisionerSystemContext)3 HashMap (java.util.HashMap)2 ProvisionerDetail (io.cdap.cdap.proto.provisioner.ProvisionerDetail)1 Provisioner (io.cdap.cdap.runtime.spi.provisioner.Provisioner)1 ProvisionerSpecification (io.cdap.cdap.runtime.spi.provisioner.ProvisionerSpecification)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1