<!--

    Copyright 2015-2017 Hewlett Packard Enterprise Development LP.

    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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.github.cafdataprocessing</groupId>
        <artifactId>processing-utilities-aggregator</artifactId>
        <version>1.2.0-49</version>
    </parent>

    <artifactId>data-processing-task-submitter-container</artifactId>
    <packaging>pom</packaging>

    <dependencies>
        <dependency>
            <groupId>com.github.cafdataprocessing</groupId>
            <artifactId>data-processing-task-submitter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <CAF_RABBITMQ_PUBLISH_QUEUE>dataprocessing-fs-workflow-in</CAF_RABBITMQ_PUBLISH_QUEUE>
        <CAF_RABBITMQ_PASSWORD>root</CAF_RABBITMQ_PASSWORD>
        <CAF_RABBITMQ_USERNAME>root</CAF_RABBITMQ_USERNAME>

        <CAF_STORAGE_DATA_DIRECTORY>${test.webdav.directory}</CAF_STORAGE_DATA_DIRECTORY>

        <CAF_TASKSUBMITTER_DOCUMENT_INPUT_DIRECTORY>/input</CAF_TASKSUBMITTER_DOCUMENT_INPUT_DIRECTORY>
        <CAF_TASKSUBMITTER_PROJECTID>DefaultProjectId</CAF_TASKSUBMITTER_PROJECTID>
        <CAF_TASKSUBMITTER_WORKFLOW_ID>1</CAF_TASKSUBMITTER_WORKFLOW_ID>

        <caf.container.tasksubmitter>${dockerDataProcessingOrg}data-processing-task-submitter${dockerProjectVersion}</caf.container.tasksubmitter>
        <test.webdav.directory>/srv/common/webdav</test.webdav.directory>
    </properties>

    <build>
        <plugins>
            <!-- Compile test sources. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <executions>
                    <execution>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                        <configuration>
                            <testCompilerArgument>-parameters</testCompilerArgument>
                            <source>1.8</source>
                            <target>1.8</target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.failsafe.version}</version>
                <executions>
                    <execution>
                        <id>webservice-Docker</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <!-- use debugForkedProcess to enable debugging of tests during a run -->
                    <!--<debugForkedProcess>true</debugForkedProcess>-->
                    <systemPropertyVariables>
                        <CAF_RABBITMQ_HOST>${docker.host.address}</CAF_RABBITMQ_HOST>
                        <CAF_RABBITMQ_PORT>${rabbitmq.node.port}</CAF_RABBITMQ_PORT>
                        <CAF_RABBITMQ_USERNAME>${CAF_RABBITMQ_USERNAME}</CAF_RABBITMQ_USERNAME>
                        <CAF_RABBITMQ_PASSWORD>${CAF_RABBITMQ_PASSWORD}</CAF_RABBITMQ_PASSWORD>
                        <CAF_RABBITMQ_PUBLISH_QUEUE>${CAF_RABBITMQ_PUBLISH_QUEUE}</CAF_RABBITMQ_PUBLISH_QUEUE>

                        <CAF_STORAGE_DATA_DIRECTORY>${CAF_STORAGE_DATA_DIRECTORY}</CAF_STORAGE_DATA_DIRECTORY>

                        <CAF_TASKSUBMITTER_DOCUMENT_INPUT_DIRECTORY>${CAF_TASKSUBMITTER_DOCUMENT_INPUT_DIRECTORY}</CAF_TASKSUBMITTER_DOCUMENT_INPUT_DIRECTORY>
                        <CAF_TASKSUBMITTER_PROJECTID>${CAF_TASKSUBMITTER_PROJECTID}</CAF_TASKSUBMITTER_PROJECTID>
                        <CAF_TASKSUBMITTER_WORKFLOW_ID>${CAF_TASKSUBMITTER_WORKFLOW_ID}</CAF_TASKSUBMITTER_WORKFLOW_ID>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>${fabric8.docker.maven.version}</version>
                <executions>
                    <execution>
                        <id>docker-build</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>docker-start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>docker-stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>docker-push</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                        <configuration>
                            <!-- only upload the task-submitter image, other images are built as part of testing -->
                            <filter>data-processing-task-submitter</filter>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <autoPull>always</autoPull>
                    <images>
                        <!-- RabbitMQ image for for testing Task Submitter image starts -->
                        <image>
                            <alias>rabbitmq</alias>
                            <name>rabbitmq:3-management</name>
                            <run>
                                <ports>
                                    <port>${rabbitmq.ctrl.port}:15672</port>
                                    <port>${rabbitmq.node.port}:5672</port>
                                </ports>
                                <env>
                                    <RABBITMQ_DEFAULT_PASS>${CAF_RABBITMQ_PASSWORD}</RABBITMQ_DEFAULT_PASS>
                                    <RABBITMQ_DEFAULT_USER>${CAF_RABBITMQ_USERNAME}</RABBITMQ_DEFAULT_USER>
                                </env>
                                <wait>
                                    <log>Server startup complete</log>
                                    <http>
                                        <url>http://${docker.host.address}:${rabbitmq.ctrl.port}</url>
                                    </http>
                                    <time>120000</time>
                                    <shutdown>500</shutdown>
                                </wait>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                            </run>
                        </image>

                        <!-- Image to act as a data store FS location -->
                        <image>
                            <alias>data-store</alias>
                            <name>cloudesire/webdav</name>
                            <run>
                                <volumes>
                                    <bind>
                                        <volume>${test.webdav.directory}</volume>
                                    </bind>
                                </volumes>
                                <ports>
                                    <port>${webdav.apache.port}:8080</port>
                                </ports>
                                <env>
                                    <APACHE_PORT>8080</APACHE_PORT>
                                </env>
                                <wait>
                                    <log>WebDAV Server startup complete</log>
                                    <http>
                                        <url>http://${docker.host.address}:${webdav.apache.port}</url>
                                    </http>
                                    <time>120000</time>
                                    <shutdown>500</shutdown>
                                </wait>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                            </run>
                        </image>

                        <!-- Input files -->
                        <image>
                            <alias>input-files</alias>
                            <name>input-files</name>
                            <build>
                                <assembly>
                                    <basedir>/input</basedir>
                                    <inline>
                                        <fileSets>
                                            <fileSet>
                                                <directory>test-data</directory>
                                                <outputDirectory>/</outputDirectory>
                                                <includes>
                                                    <include>*</include>
                                                </includes>
                                            </fileSet>
                                        </fileSets>
                                    </inline>
                                </assembly>
                            </build>
                        </image>
                        <!-- Task Submitter Container Image -->
                        <image>
                            <alias>data-processing-task-submitter</alias>
                            <name>${caf.container.tasksubmitter}</name>
                            <build>
                                <from>java:8</from>
                                <labels>
                                    <Build.Number>${project.version}</Build.Number>
                                    <Build.Date>${maven.build.timestamp}</Build.Date>
                                    <Git.Branch>${git.branch}</Git.Branch>
                                    <Git.Commit>${git.revision}</Git.Commit>
                                </labels>
                                <optimise>true</optimise>
                                <assembly>
                                    <basedir>/</basedir>
                                    <inline>
                                        <dependencySets>
                                            <dependencySet>
                                                <fileMode>0755</fileMode>
                                                <useProjectArtifact>true</useProjectArtifact>
                                                <includes>
                                                    <include>com.github.cafdataprocessing:data-processing-task-submitter</include>
                                                </includes>
                                                <outputFileNameMapping>task-submitter.jar</outputFileNameMapping>
                                            </dependencySet>
                                        </dependencySets>
                                        <fileSets>
                                            <fileSet>
                                                <directory>/base-data</directory>
                                                <outputDirectory>/base-data</outputDirectory>
                                                <lineEnding>unix</lineEnding>
                                                <includes>
                                                    <include>*.json</include>
                                                </includes>
                                                <fileMode>0755</fileMode>
                                            </fileSet>
                                        </fileSets>
                                    </inline>
                                </assembly>
                                <env>
                                    <!-- setting base data environment variables to point to default container data locations -->
                                    <CAF_TASKSUBMITTER_BASEDATA_BOILERPLATE_INPUT_FILE>/base-data/example_boilerplate.json</CAF_TASKSUBMITTER_BASEDATA_BOILERPLATE_INPUT_FILE>
                                    <CAF_TASKSUBMITTER_BASEDATA_CLASSIFICATION_INPUT_FILE>/base-data/example_classification_workflow.json</CAF_TASKSUBMITTER_BASEDATA_CLASSIFICATION_INPUT_FILE>
                                    <CAF_TASKSUBMITTER_BASEDATA_WORKFLOW_INPUT_FILE>/base-data/example_workflow.json</CAF_TASKSUBMITTER_BASEDATA_WORKFLOW_INPUT_FILE>
                                    <!-- Defaulting this to same value as used in the example boilerplate base data -->
                                    <CAF_TASKSUBMITTER_PROJECTID>Default</CAF_TASKSUBMITTER_PROJECTID>
                                </env>
                                <cmd>
                                    java -jar task-submitter.jar
                                </cmd>
                            </build>
                            <run>
                                <links>
                                    <link>rabbitmq</link>
                                </links>
                                <volumes>
                                    <from>
                                        <image>data-store</image>
                                        <image>input-files</image>
                                    </from>
                                </volumes>
                                <wait>
                                    <log>Monitoring directory for new documents.</log>
                                    <time>50000</time>
                                    <shutdown>500</shutdown>
                                </wait>
                                <env>
                                    <CAF_RABBITMQ_HOST>rabbitmq</CAF_RABBITMQ_HOST>
                                    <CAF_RABBITMQ_PORT>5672</CAF_RABBITMQ_PORT>
                                    <CAF_RABBITMQ_USERNAME>${CAF_RABBITMQ_USERNAME}</CAF_RABBITMQ_USERNAME>
                                    <CAF_RABBITMQ_PASSWORD>${CAF_RABBITMQ_PASSWORD}</CAF_RABBITMQ_PASSWORD>
                                    <CAF_RABBITMQ_PUBLISH_QUEUE>${CAF_RABBITMQ_PUBLISH_QUEUE}</CAF_RABBITMQ_PUBLISH_QUEUE>
                                    <CAF_RABBITMQ_MAX_PRIORITY>32</CAF_RABBITMQ_MAX_PRIORITY>

                                    <CAF_STORAGE_DATA_DIRECTORY>${CAF_STORAGE_DATA_DIRECTORY}</CAF_STORAGE_DATA_DIRECTORY>

                                    <CAF_TASKSUBMITTER_DOCUMENT_INPUT_DIRECTORY>${CAF_TASKSUBMITTER_DOCUMENT_INPUT_DIRECTORY}</CAF_TASKSUBMITTER_DOCUMENT_INPUT_DIRECTORY>
                                    <CAF_TASKSUBMITTER_PROJECTID>${CAF_TASKSUBMITTER_PROJECTID}</CAF_TASKSUBMITTER_PROJECTID>
                                    <CAF_TASKSUBMITTER_WORKFLOW_ID>${CAF_TASKSUBMITTER_WORKFLOW_ID}</CAF_TASKSUBMITTER_WORKFLOW_ID>
                                </env>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                            </run>
                        </image>
                    </images>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>use-default-fixed-ports</id>
            <properties>
                <rabbitmq.node.port>5672</rabbitmq.node.port>
                <rabbitmq.ctrl.port>15672</rabbitmq.ctrl.port>
            </properties>
        </profile>
        <profile>
            <id>skip-build-docker-container</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>${fabric8.docker.maven.version}</version>
                        <executions>
                            <execution>
                                <id>build-docker-container</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <skip>true</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>skip-start-docker-container</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>${fabric8.docker.maven.version}</version>
                        <executions>
                            <execution>
                                <id>start</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                                <configuration>
                                    <skip>true</skip>
                                </configuration>
                            </execution>
                            <!-- Stop the containers in post-integration-test phase. -->
                            <execution>
                                <id>stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                                <configuration>
                                    <skip>true</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
