All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.polyapi.plugin.mojo.DeployFunctionsMojo Maven / Gradle / Ivy

There is a newer version: 0.15.3
Show newest version
package io.polyapi.plugin.mojo;

import io.polyapi.plugin.model.function.PolyFunction;
import io.polyapi.plugin.service.DeploymentService;
import io.polyapi.plugin.service.DeploymentServiceImpl;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static com.google.common.base.Predicates.equalTo;
import static java.lang.String.join;
import static java.util.function.Predicate.not;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE_PLUS_RUNTIME;

@Slf4j
@Setter
@Mojo(name = "deploy-functions", requiresDependencyResolution = COMPILE_PLUS_RUNTIME)
public class DeployFunctionsMojo extends PolyApiMojo {

    @Parameter(property = "functions")
    private String functions;

    @Parameter(property = "dry-run", defaultValue = "false")
    private boolean dryRun;

    @Override
    protected void execute(String host, Integer port) {
        log.info("Initiating deployment of Poly functions.");
        DeploymentService polyFunctionService = new DeploymentServiceImpl(getHttpClient(), getJsonParser(), getMavenService(), host, port);
        List functionFilters = Arrays.stream(Optional.ofNullable(functions).orElse("").split(","))
                .map(String::trim)
                .filter(not(equalTo("")))
                .toList();
        log.debug("Function filters: \"{}\"", join("\", \"", functionFilters));
        if (dryRun) {
            log.warn("Dry run mode is set. This won't deploy to server.");
        }
        List deployedFunctions = polyFunctionService.deployFunctions(functionFilters, dryRun);
        log.info("Deployed {} functions:", deployedFunctions.size());
        deployedFunctions.forEach(deployedFunction -> {
            log.info("    - Deployed function '{}' on context '{}' with id '{}'", deployedFunction.getSignature(), deployedFunction.getContext(), deployedFunction.getId());
        });
        log.info("Poly functions deployment complete.");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy