com.edmunds.tools.databricks.maven.BaseDatabricksUpsertClusterMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of databricks-maven-plugin Show documentation
Show all versions of databricks-maven-plugin Show documentation
A databricks maven plugin to automate databricks deployments as part of a build
/*
* Copyright 2019 Edmunds.com, 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.edmunds.tools.databricks.maven;
import com.edmunds.rest.databricks.DTO.UpsertClusterDTO;
import com.edmunds.tools.databricks.maven.model.EnvironmentDTO;
import com.edmunds.tools.databricks.maven.util.EnvironmentDTOSupplier;
import com.edmunds.tools.databricks.maven.util.SettingsInitializer;
import com.edmunds.tools.databricks.maven.util.SettingsUtils;
import java.io.File;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
/**
* Base class for Databricks UpsertCluster Mojos.
*/
public abstract class BaseDatabricksUpsertClusterMojo extends BaseDatabricksMojo {
/**
* The databricks cluster json file that contains all of the information for how to create databricks cluster.
*/
@Parameter(
defaultValue = "${project.build.resources[0].directory}/databricks-plugin/databricks-cluster-settings.json",
property = "dbClusterFile")
protected File dbClusterFile;
// These fields are being instantiated within getters to await @Parameter fields initialization
private SettingsUtils settingsUtils;
private EnvironmentDTOSupplier environmentDTOSupplier;
private SettingsInitializer settingsInitializer;
/**
* Get SettingsUtils.
*
* @return SettingsUtils
* @throws MojoExecutionException exception
*/
public SettingsUtils getSettingsUtils() throws MojoExecutionException {
if (settingsUtils == null) {
settingsUtils = new SettingsUtils<>(
UpsertClusterDTO[].class, "/default-cluster.json", dbClusterFile,
getEnvironmentDTOSupplier(), getSettingsInitializer());
}
return settingsUtils;
}
EnvironmentDTOSupplier getEnvironmentDTOSupplier() {
if (environmentDTOSupplier == null) {
environmentDTOSupplier = () -> {
if (StringUtils.isBlank(databricksRepo)) {
throw new MojoExecutionException("databricksRepo property is missing");
}
return new EnvironmentDTO(project, environment, databricksRepo, databricksRepoKey, prefixToStrip);
};
}
return environmentDTOSupplier;
}
SettingsInitializer getSettingsInitializer() {
if (settingsInitializer == null) {
settingsInitializer = new BaseDatabricksUpsertClusterMojoSettingsInitializer(validate);
}
return settingsInitializer;
}
}