tosca_definitions_version: alien_dsl_2_0_0

metadata:
  template_name: get_secrets
  template_version: 0.1.0-SNAPSHOT
  template_author: admin

imports:
  - normative-types: <yorc-types.yml>

topology_template:
  node_templates:
    JDK:
      type: org.alien4cloud.lang.java.jdk.linux.nodes.OracleJDK
      properties:
        java_url: "https://edelivery.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz"
        java_home: { get_secret: ["/secrets/myapp/javahome", java_opt1=1, java_opt2=2]}
        component_version: "8.101"
      requirements:
        - host:
            node: Front
            capability: tosca.capabilities.Container
            relationship: tosca.relationships.HostedOn
    Tomcat:
      type: org.alien4cloud.nodes.Tomcat
      properties:
        tomcat_home: "/opt/tomcat"
        download_url: "https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.39/bin/apache-tomcat-8.0.39.tar.gz"
        component_version: "8.0.39"
      requirements:
        - host:
            node: JDK
            capability: org.alien4cloud.lang.java.pub.capabilities.JDK
            relationship: org.alien4cloud.lang.java.pub.relationships.JavaSoftwareHostedOnJDK
      capabilities:
        data_endpoint:
          properties:
            port: { get_secret: ["/secrets/myapp/tomcatport", tom_opt1=1, tom_opt2=2]}
            secure: false
            initiator: source
        admin_endpoint:
          properties:
            secure: true
            protocol: tcp
            network_name: PRIVATE
            initiator: source
    Front:
      type: tosca.nodes.Compute
      capabilities:
        os:
          properties:
            architecture: "x86_64"
            type: linux
            distribution: ubuntu
        scalable:
          properties:
            min_instances: 1
            max_instances: 1
            default_instances: 1
        endpoint:
          properties:
            secure: true
            protocol: tcp
            network_name: PRIVATE
            initiator: source

node_types:
  org.alien4cloud.lang.java.pub.nodes.JavaSoftware:
    abstract: true
    derived_from: tosca.nodes.Root
    description: The JavaSoftware node represents a generic software component that can be launch by Java.
    metadata:
      icon: images/javabean.png
    requirements:
      - java:
          capability: org.alien4cloud.lang.java.pub.capabilities.JDK
          relationship: org.alien4cloud.lang.java.pub.relationships.JavaSoftwareHostedOnJDK
          occurrences: [1, 1]
  org.alien4cloud.lang.java.jdk.linux.nodes.OracleJDK:
    derived_from: tosca.nodes.SoftwareComponent
    description: Installation of Oracle Java Development Kit
    metadata:
      icon: images/jdk.png
    properties:
      java_url:
        type: string
        required: true
        default: "https://edelivery.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz"
      java_home:
        type: string
        required: true
        default: "/opt/java"
      component_version:
        type: version
        default: 1.8.0-131-b11
    attributes:
      java_version: { get_operation_output: [ SELF, Standard, create, JAVA_VERSION ] }
      java_message: { concat: ["Java help: ", get_operation_output: [ SELF, Standard, create, JAVA_HELP ]] }
      java_secret: { get_secret: ["/secrets/app/javatype"]}
    capabilities:
      jdk:
        type: org.alien4cloud.lang.java.pub.capabilities.JDK
        occurrences: [ 0, UNBOUNDED ]
    interfaces:
      Standard:
        create:
          inputs:
            JAVA_URL: { get_property: [SELF, java_url] }
            JAVA_HOME: { get_property: [SELF, java_home] }
            JAVA_INPUT_SEC: {get_secret: ["/secrets/app/javatype", ji_o]}
          implementation: scripts/install_jdk.sh
  org.alien4cloud.java.pub.nodes.JavaSoftware:
    abstract: true
    derived_from: tosca.nodes.Root
    description: The JavaSoftware node represents a generic software component that can be launch by Java.
    metadata:
      icon: images/javabean.png
    requirements:
      - java:
          capability: org.alien4cloud.java.pub.capabilities.JDK
          relationship: org.alien4cloud.java.pub.relationships.JavaSoftwareHostedOnJDK
          occurrences: [1, 1]
  org.alien4cloud.java.jdk.linux.nodes.OracleJDK:
    derived_from: tosca.nodes.SoftwareComponent
    description: Installation of Oracle Java Development Kit
    metadata:
      icon: images/jdk.png
    properties:
      java_url:
        type: string
        required: true
        default: "https://edelivery.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz"
      java_home:
        type: string
        required: true
        default: "/opt/java"
      component_version:
        type: version
        default: 1.8.0-131-b11
    attributes:
      java_version: { get_operation_output: [ SELF, Standard, create, JAVA_VERSION ] }
      java_message: { concat: ["Java help: ", get_operation_output: [ SELF, Standard, create, JAVA_HELP ]] }
    capabilities:
      jdk:
        type: org.alien4cloud.java.pub.capabilities.JDK
        occurrences: [ 0, UNBOUNDED ]
    interfaces:
      Standard:
        create:
          inputs:
            JAVA_URL: { get_property: [SELF, java_url] }
            JAVA_HOME: { get_property: [SELF, java_home] }
          implementation: scripts/install_jdk.sh
  org.alien4cloud.nodes.Tomcat:
    derived_from: tosca.nodes.WebServer
    description: >
      TOSCA node to install and run Apache Tomcat java web server.
      The Apache Tomcat® software is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies.
    metadata:
      icon: /images/tomcat.png
    properties:
      tomcat_home:
        type: string
        required: true
        description: Directory in which to install tomcat on the host.
        default: "/opt/tomcat"
      download_url:
        type: string
        required: true
        description: Url from which to download the tomcat tar.gz package
        default: "https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.39/bin/apache-tomcat-8.0.39.tar.gz"
      component_version:
        type: version
        description: Version of tomcat to install (this should match the provided download url).
        default: 8.0.39
    attributes:
      server_url: { concat: ["http://", get_attribute: [HOST, public_ip_address], ":", get_property: [SELF, data_endpoint, port]] }
    requirements:
      - host:
          capability: org.alien4cloud.lang.java.pub.capabilities.JDK
          relationship: org.alien4cloud.lang.java.pub.relationships.JavaSoftwareHostedOnJDK
          occurrences: [1, 1]
    capabilities:
      data_endpoint: # This is the application endpoint of tomcat server.
        type: tosca.capabilities.Endpoint
        occurrences: [ 0, 0 ]
        properties:
          protocol: http
          port: 8080 # set a default value for the port
      admin_endpoint: # There is a tomcat admin endpoint actually but we don't provide it here.
        type: tosca.capabilities.Endpoint.Admin
        occurrences: [ 0, 0 ]
      host: # Overrides the parent container capability
        type: org.alien4cloud.capabilities.WarContainer
        occurrences: [ 0, UNBOUNDED ]
    interfaces:
      Standard:
        create:
          inputs:
            TOMCAT_HOME: { get_property: [SELF, tomcat_home] }
            TOMCAT_PORT: { get_property: [SELF, data_endpoint, port] }
            TOMCAT_URL: { get_property: [SELF, download_url] }
          implementation: scripts/tomcat_install.sh
        start:
          inputs:
            TOMCAT_HOME: { get_property: [SELF, tomcat_home] }
            TOMCAT_PORT: { get_property: [SELF, data_endpoint, port] }
          implementation: scripts/tomcat_start.sh
        stop:
          inputs:
            TOMCAT_HOME: { get_property: [SELF, tomcat_home] }
          implementation: scripts/tomcat_stop.sh

relationship_types:
  org.alien4cloud.lang.java.pub.relationships.JavaSoftwareHostedOnJDK:
    derived_from: tosca.relationships.HostedOn
    description: Relationship use to describe that the SoftwareComponent is hosted on the JDK.
    valid_target_types: [ org.alien4cloud.lang.java.pub.capabilities.JDK ]
    interfaces:
      Configure:
        post_configure_source:
          inputs:
            TOMCAT_SEC: { get_secret: ["/secrets/app/tominput"] }
          implementation: script/my.sh
  org.alien4cloud.java.pub.relationships.JavaSoftwareHostedOnJDK:
    derived_from: tosca.relationships.HostedOn
    description: Relationship use to describe that the SoftwareComponent is hosted on the JDK.
    valid_target_types: [ org.alien4cloud.java.pub.capabilities.JDK ]
  org.alien4cloud.relationships.WarHostedOnTomcat:
    derived_from: tosca.relationships.HostedOn
    description: Relationship that allows to deploy a war on tomcat.
    valid_target_types: [ org.alien4cloud.capabilities.WarContainer ]
    interfaces:
      configure:
        pre_configure_source:
          inputs:
            CONTEXT_PATH: { get_property: [SOURCE, app_endpoint, url_path] }
            TOMCAT_HOME: { get_property: [TARGET, tomcat_home] }
            TOMCAT_PORT: { get_property: [TARGET, port] }
          implementation: scripts/tomcat_install_war.sh

capability_types:
  org.alien4cloud.lang.java.pub.capabilities.JDK:
    derived_from: tosca.capabilities.Container
  org.alien4cloud.capabilities.WarContainer:
    derived_from: tosca.capabilities.Container
  org.alien4cloud.java.pub.capabilities.JDK:
    derived_from: tosca.capabilities.Container
