public void addService()

in azure-sfmesh-maven-plugin/src/main/java/com/microsoft/azure/maven/servicefabric/AddServiceMojo.java [122:166]


    public void addService() throws MojoFailureException{
        final String serviceFabricResourcesDirectory = Utils.getServicefabricResourceDirectory(logger, project);
        final String appResourcesDirectory = Utils.getAppResourcesDirectory(logger, project);
        final String serviceDirectory = Utils.getPath(serviceFabricResourcesDirectory, serviceName);
        if (!Utils.checkIfExists(serviceFabricResourcesDirectory)){
            throw new MojoFailureException("Service fabric resources folder does not exist." +
                "Please run init goal before running this goal!");
        }
        if (!Utils.checkIfExists(Utils.getPath(appResourcesDirectory, "app_" + applicationName + ".yaml"))){
            throw new MojoFailureException(String.format("Application resource" +
                "with the name %s does not exist", applicationName));
        }
        if (Utils.checkIfExists(serviceDirectory)){
            throw new MojoFailureException("Service Resource with the specified name already exists");
        }
        String serviceContent = new YamlContent.Builder()
                .addElement("SCHEMA_VERSION", schemaVersion)
                .addElement("APP_NAME", applicationName)
                .addElement("SERVICE_NAME", serviceName)
                .addElement("SERVICE_DESCRIPTION", serviceDescription)
                .addElement("OS_TYPE", getOS())
                .addElement("CODE_PACKAGE_NAME", getCodePackageName())
                .addElement("DOCKER_IMAGE", imageName)
                .addElement("LISTENER_NAME", getListenerName())
                .addElement("LISTENER_PORT", listenerPort)
                .addElement("CPU_USAGE", cpuUsage)
                .addElement("MEMORY_USAGE", memoryUsage)
                .addElement("REPLICA_COUNT", replicaCount)
                .addElement("NETWORK_NAME", networkRef)
                .build(logger, Constants.SERVICE_RESOURCE_NAME);
        try {
            if (!environmentalVariables.equals(Constants.DEFAULT_ENVIRONMENTAL_VARIABLES)){
                serviceContent = addEnvironmentVariables(logger, serviceContent, environmentalVariables);
            }
            Utils.createDirectory(logger, serviceDirectory);
            FileUtils.fileWrite(Utils.getPath(serviceDirectory,
                "service_" + serviceName + ".yaml"), serviceContent);
            logger.debug(String.format("Wrote %s service content to output", serviceName));
            TelemetryHelper.sendEvent(TelemetryEventType.ADDSERVICE,
                String.format("Added service with name: %s", serviceName), logger);
        } catch (IOException e) {
            logger.error(e);
            throw new MojoFailureException("Error while writing output");
        }
    }