Generating CBA With Maven Archetypes

In this tutorial, we will create a CBA using the archetype-blueprint Archetypes and compile and deploy it. Before you begin, you will need to have installed Maven, but you no longer need to manually install the archetype-blueprin Archetypes as they are in the Central Nexus Repository now, so you just need to make sure your mvn settings.xml file points to this repo. 

Maven archetypes can be thought of as templates that are installed into the Maven environment and can be used to generate new applications from scratch that are pre-configured for certain environments. We use this to generate CBA boilerplate code.

Boilerplate CBA from the command line.

Requirement:  Please add the following repository to your maven settings.xml once. This helps the maven-archetype-plugin to fetch the correct archetype.

 <repositories>
    ---
    <repository>
        <!-- id expected by maven-archetype-plugin to avoid fetching from everywhere -->
        <id>archetype</id>
        <url>http://nexus.onap.org/content/repositories/snapshots</url>
        <releases>
          <enabled>true</enabled>
          <checksumPolicy>fail</checksumPolicy>
        </releases>
        <snapshots>
          <enabled>true</enabled>
          <checksumPolicy>warn</checksumPolicy>
        </snapshots>
    </repository>
    ---
</repositories>


  1. Start by opening up a command prompt and navigating to the directory your project will reside in
  2. The easy way to create a project on the command line is to just type

    1

    mvn archetype:generate -DarchetypeCatalog=remote

    We will use the easier version where we don’t have to specify long command lines that include the group and archetype Ids and versions.

  3. You will be greeted with a long list of possible archetypes with a number next to them and a prompt at the bottom to enter the number of the archetype you want to use.

    Choose archetype:
    1: remote -> org.onap.policy.drools-applications:archetype-cl-amsterdam (Archetype to generate a yaml based control loop for ONAP Amsterdam release)
    2: remote -> org.onap.policy.drools-applications.controlloop.templates:archetype-cl-amsterdam (Archetype to generate a yaml based control loop for ONAP Amsterdam release)
    3: remote -> org.onap.policy.drools-applications.controlloop.templates:archetype-cl-casablanca (Archetype to generate a yaml based control loop for ONAP Casablanca release)
    ...
    ...
    9: remote -> org.onap.ccsdk.cds.components.cba:archetype-blueprint (CDS Micro-services Archetype CBA)

    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 
  4. Enter the number of the archetype-blueprint archetype you want to use and press enter.

    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 9
  5. You will then be asked to accept a number of default properties for the cba. If you don't want to use any of the defaults then simply press "n" at the end and hit enter -otherwise press "Y' and hit enter.

    [INFO] Using property: groupId = org.onap.ccsdk.cds.components.cba
    [INFO] Using property: artifactId = test-cba
    Define value for property 'version' 1.0-SNAPSHOT: : 
    [INFO] Using property: package = org.onap.ccsdk.cds.components.cba
    [INFO] Using property: cdsPassword = ccsdkapps
    [INFO] Using property: cdsUsername = ccsdkapps
    Confirm properties configuration:
    groupId: org.onap.ccsdk.cds.components.cba
    artifactId: test-cba
    version: 1.0-SNAPSHOT
    package: org.onap.ccsdk.cds.components.cba
    cdsPassword: ccsdkapps
    cdsUsername: ccsdkapps
     Y: : n

    Since for the sake of demonstration, I have entered "n" then I was given the prompt to change these default values. I changed test-cba to test-cba2.

    Define value for property 'groupId' org.onap.ccsdk.cds.components.cba: : 
    Define value for property 'artifactId' test-cba: : test-cba2
    Define value for property 'version' 1.0-SNAPSHOT: : 
    Define value for property 'package' org.onap.ccsdk.cds.components.cba: : 
    Define value for property 'cdsPassword' ccsdkapps: : 
    Define value for property 'cdsUsername' ccsdkapps: : 
    Confirm properties configuration:
    groupId: org.onap.ccsdk.cds.components.cba
    artifactId: test-cba2
    version: 1.0-SNAPSHOT
    package: org.onap.ccsdk.cds.components.cba
    cdsPassword: ccsdkapps
    cdsUsername: ccsdkapps

     Y: : y

    [INFO] ----------------------------------------------------------------------------
    [INFO] Using following parameters for creating project from Archetype: archetype-blueprint:1.0.0-SNAPSHOT
    [INFO] ----------------------------------------------------------------------------
    [INFO] Parameter: groupId, Value: org.onap.ccsdk.cds.components.cba
    [INFO] Parameter: artifactId, Value: test-cba2
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] Parameter: package, Value: org.onap.ccsdk.cds.components.cba
    [INFO] Parameter: packageInPathFormat, Value: org/onap/ccsdk/cds/components/cba
    [INFO] Parameter: package, Value: org.onap.ccsdk.cds.components.cba
    [INFO] Parameter: groupId, Value: org.onap.ccsdk.cds.components.cba
    [INFO] Parameter: artifactId, Value: test-cba2
    [INFO] Parameter: cdsUsername, Value: ccsdkapps
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] Parameter: cdsPassword, Value: ccsdkapps
    [INFO] Project created from Archetype in dir: /Users/kuldipr/Documents/Temp/test-cba2
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  32.565 s
    [INFO] Finished at: 2021-05-21T17:15:21-04:00
    [INFO] ------------------------------------------------------------------------
  6. Once complete, if you look in the directory you will see a new directory called test-cba2 or what ever name you picked for cba. Move into this directory 

    your-machine:Temp$ ls
    test-cba2

    your-machine:Temp$ cd test-cba2/
    your-machine:test-cba2$ ls
    Definitions Scripts TOSCA-Metadata Tests pom.xml
  7. You can now build this cba.

    your-machine:test-cba2$ mvn clean install
    [INFO] Scanning for projects...
    Downloading from onap-staging: https://nexus.onap.org/content/groups/staging/org/onap/ccsdk/parent/dependencies-bom/2.1.0-SNAPSHOT/maven-metadata.xml
    ...
    ...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  24.851 s
    [INFO] Finished at: 2021-05-21T17:30:17-04:00
    [INFO] ------------------------------------------------------------------------
  8. You can now deploy it.

    your-machine:test-cba2$ mvn install -Pdeploy-cba
    [INFO] Scanning for projects...
    Downloading from onap-public: https://nexus.onap.org/content/groups/public/org/onap/ccsdk/parent/dependencies-bom/2.1.0-SNAPSHOT/maven-metadata.xml
    ...
    ...
    [INFO] Created enriched cba: test-cba2-1.1.0-SNAPSHOT-enriched-cba.zip
    [INFO] CBA Deployed
    [INFO] {"blueprintModel":{"id":"d99744e8-969b-452e-a4f2-e822a6087907","artifactUUId":null,"artifactType":"SDNC_MODEL","artifactVersion":"1.0.0",
    "artifactDescription":"Controller Blueprint for RT-test-kotlin:1.0.0","internalVersion":null,"createdDate":"2021-05-21T21:32:44.000Z",
    "artifactName":"RT-test-kotlin","published":"Y","updatedBy":"Selffish","tags":"test, regression"}}

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  24.639 s
    [INFO] Finished at: 2021-05-21T17:32:45-04:00
    [INFO] ------------------------------------------------------------------------