Saturday, January 29, 2022

Using Maven with Weblogic 14.1.1

 HOWTO

 

GitHub

 

Set env 

dave@dave dave-basic-webapp-ejb-project]$ . /app/weblogic/wlserver/server/bin/setWLSEnv.sh
CLASSPATH=/usr/java/jdk-11.0.13/lib/tools.jar:/home/app/weblogic/wlserver/modules/features/wlst.wls.classpath.jar:

PATH=/home/app/weblogic/wlserver/server/bin:/home/app/weblogic/wlserver/../oracle_common/modules/thirdparty/org.apache.ant/1.10.5.0.0/apache-ant-1.10.5/bin:/usr/java/jdk-11.0.13/bin:/usr/java/jdk-11.0.13/bin:/app/weblogic/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1//bin:/app/weblogic-14.1.1/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1//bin:/home/dave/.local/bin:/home/dave/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/app/weblogic/oracle_common/modules/thirdparty/apache-maven_bundle/3.6.1.0.0/apache-maven-3.6.1//bin

Your environment has been set.

 

Compile and deploy the project - requires Maven configuration - see below 

Use Weblogic path /app/weblogic - Maven plugin had issues with Oracle JARs synced to local repository 

Error "java.lang.NoClassDefFoundError Required class missing : weblogic/Deployer" After deleting com/oracle/weblogic in Maven local repo and resync deploy works

dave@dave dave-basic-webapp-ejb-project]$ mvn  clean  compile package  pre-integration-test 
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< dave:dave-basic-webapp-ejb-project >-----------------
[INFO] Building basicWebappEjb 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ dave-basic-webapp-ejb-project ---
[INFO] Deleting /git/weblogic/dave-basic-webapp-ejb-project/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ dave-basic-webapp-ejb-project ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 6 source files to /git/weblogic/dave-basic-webapp-ejb-project/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ dave-basic-webapp-ejb-project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /git/weblogic/dave-basic-webapp-ejb-project/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ dave-basic-webapp-ejb-project ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dave-basic-webapp-ejb-project ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ dave-basic-webapp-ejb-project ---
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/home/dave/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar) to field java.util.Properties.defaults
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Packaging webapp
[INFO] Assembling webapp [dave-basic-webapp-ejb-project] in [/git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb]
[INFO] Processing war project
[INFO] Copying webapp resources [/git/weblogic/dave-basic-webapp-ejb-project/src/main/webapp]
[INFO] Webapp assembled in [105 msecs]
[INFO] Building war: /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ dave-basic-webapp-ejb-project ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dave-basic-webapp-ejb-project ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /git/weblogic/dave-basic-webapp-ejb-project/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ dave-basic-webapp-ejb-project ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ dave-basic-webapp-ejb-project ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ dave-basic-webapp-ejb-project ---
[INFO] Packaging webapp
[INFO] Assembling webapp [dave-basic-webapp-ejb-project] in [/git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb]
[INFO] Processing war project
[INFO] Copying webapp resources [/git/weblogic/dave-basic-webapp-ejb-project/src/main/webapp]
[INFO] Webapp assembled in [66 msecs]
[INFO] Building war: /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- weblogic-maven-plugin:14.1.1-0-0:deploy (default) @ dave-basic-webapp-ejb-project ---
[INFO] Command flags are: -noexit -deploy -username weblogic -password ******* -name basicWebappEjb -source /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war -verbose -adminurl t3://127.0.0.1:7001
weblogic.Deployer invoked with options:  -noexit -deploy -username weblogic -name basicWebappEjb -source /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war -verbose -adminurl t3://127.0.0.1:7001
<Jan 30, 2022, 9:00:58 AM Central European Standard Time> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, basicWebappEjb [archive: /git/weblogic/dave-basic-webapp-ejb-project/target/basicWebappEjb.war], to configured targets.> 
Task 6 initiated: [Deployer:149026]deploy application basicWebappEjb on AdminServer.
Task 6 completed: [Deployer:149026]deploy application basicWebappEjb on AdminServer.
Target state: deploy completed on Server AdminServer

Target Assignments:
+ basicWebappEjb  AdminServer
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  10.671 s
[INFO] Finished at: 2022-01-30T09:01:01+01:00
[INFO] ------------------------------------------------------------------------


 


Install Oracle plugin to local repository

Follow instructions from Oracle Weblogic 14.1.1 HOWTO https://docs.oracle.com/en/middleware/standalone/weblogic-server/14.1.1.0/wlprg/maven.html#GUID-C6FC7582-2D1C-4EA5-B000-71AE9A2F2B05 

 


  cd /app/weblogic-14.1.1/
  find . -name   oracle*maven-*.jar
  cd  ./oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/14.1.1/

  ls ~/.m2/repository/
  mvn install:install-file -DpomFile=oracle-maven-sync-14.1.1.pom -Dfile=oracle-maven-sync-14.1.1.jar
  mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=/app/weblogic-14.1.1/
  mvn archetype:crawl -Dcatalog=$HOME/.m2/archetype-catalog.xml

  List plugins goals

[dave@dave dave-basic-webapp-ejb-project]$ mvn help:describe -DgroupId=com.oracle.weblogic -DartifactId=weblogic-maven-plugin -Dversion=14.1.1-0-0
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< dave:dave-basic-webapp-ejb-project >-----------------
[INFO] Building basicWebappEjb 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- maven-help-plugin:3.2.0:describe (default-cli) @ dave-basic-webapp-ejb-project ---
[INFO] com.oracle.weblogic:weblogic-maven-plugin:14.1.1-0-0

Name: weblogic-maven-plugin
Description: The Oracle WebLogic Server 12.3.1 Maven plugin
Group Id: com.oracle.weblogic
Artifact Id: weblogic-maven-plugin
Version: 14.1.1-0-0
Goal Prefix: weblogic

This plugin has 23 goals:

weblogic:appc
  Description: This goal is a wrapper for the weblogic.appc compiler.

weblogic:create-domain
  Description: Create a domain for WebLogic Server using the default domain
    template. For more complex domain creation use the WLST goal. Note:
    Starting in WLS 12.2.1, there is a single unified version of WLST that
    automatically includes the WLST environment from all products in the
    ORACLE_HOME.

weblogic:deploy
  Description: Deploys an application to WebLogic Server (supports all
    formats WAR, JAR, RAR, EAR, etc.)

weblogic:distribute-app
  Description: Prepares deployment files for deployment by copying deployment
    files to target servers and validating them.

weblogic:install
  Description: Installs WebLogic Server

weblogic:list-apps
  Description: Lists the deployment names for applications and stand-alone
    modules deployed distributed, or installed to the domain

weblogic:purge-tasks
  Description: Flushes out retired deployment tasks

weblogic:redeploy
  Description: Redeploys a running application or part of a running
    application

weblogic:remove-domain
  Description: This class provides basic capabilities to remove a domain
    directory.

weblogic:start-app
  Description: Starts an application

weblogic:start-server
  Description: Starts WebLogic Server.

weblogic:stop-app
  Description: Stops an application

weblogic:stop-server
  Description: This goals run a stop script to stop WebLogic Server.

weblogic:undeploy
  Description: Stops the deployment unit and removes staged files from target
    servers

weblogic:uninstall
  Description: Uninstalls WebLogic Server

weblogic:update-app
  Description: Updates an application's deployment plan by redistributing the
    plan files and reconfiguring the application based on the new plan
    contents.

weblogic:wlst
  Description: This goal is a wrapper for the WLST scripting tool.
    Note: Starting in WLS 12.2.1, there is a single unified version of WLST
    that automatically includes the WLST environment from all products in the
    ORACLE_HOME.

weblogic:wlst-client
  Description: WLST wrapper for Maven that does not require a server install
    for WLST online commands.

weblogic:ws-clientgen
  Description: A Maven goal to generate client web service artifacts from a
    WSDL Note the differences between clientgen Ant task and Maven goal:
    clientgen goal only generates JAXWS web service artifacts, while Ant task
    has JAXRPC as the default. At the moment there is no way to direct
    clientgen goal to also compile and package generated artifacts.
  Deprecated. No reason given

weblogic:ws-jwsc
  Description: This goal builds a JAX-WS web service, generates source code,
    data binding artifacts, deployment descriptors, and so on into an output
    directory.
  Deprecated. No reason given

weblogic:ws-wsdlc
  Description: This goal generates, from an existing WSDL file, a set of
    artifacts that together provide a partial Java implementation of the Web
    Service described by the WSDL file.
  Deprecated. No reason given

weblogic:wsgen
  Description: Reads a JAX-WS service endpoint implementation class and
    generates all of the portable artifacts for a JAX-WS web service.

weblogic:wsimport
  Description: Parses wsdl and binding files and generates Java code needed
    to access it.

For more information, run 'mvn help:describe [...] -Ddetail'

Create project using Eclipse and Maven archetype 


 

 

Saturday, December 25, 2021

Set active sound port to headphones on Linux Fedora Gnome

 HOWTO

 

Get current sound settings
[dave@dave ~]$ pactl list short sinks
44    alsa_output.pci-0000_00_1f.3.analog-stereo    PipeWire    s32le 2ch 48000Hz    RUNNING

[dave@dave ~]$ more ~/.local/state/wireplumber/default-routes 
[default-routes]
alsa_card.pci-0000_00_1f.3:input:analog-input-headset-mic:channelMap=FL;FR;
alsa_card.pci-0000_00_1f.3:input:analog-input-headset-mic:channelVolumes=0.39999160170555;0.39999160170555;
alsa_card.pci-0000_00_1f.3:input:analog-input-headset-mic:latencyOffsetNsec=0
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones:channelMap=FL;FR;
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones:channelVolumes=1.0;1.0;
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones:latencyOffsetNsec=0
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker:channelMap=FL;FR;
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker:channelVolumes=0.39999160170555;0.39999160170555;
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker:latencyOffsetNsec=0
alsa_card.pci-0000_00_1f.3:profile:output:analog-stereo+input:analog-stereo=analog-output-headphones;

Set active port - change to headphones

[dave@dave ~]$ man pactl
[dave@dave ~]$ pactl list sinks |& grep -E "Sink|Ports|analog-ou"
Sink #44
        media.class = "Audio/Sink"
    Ports:
        analog-output-speaker: Speakers (type: Speaker, priority: 10000, availability group: Legacy 3, availability unknown)
        analog-output-headphones: Headphones (type: Headphones, priority: 9900, availability group: Legacy 2, availability unknown)
    Active Port: analog-output-speaker
[dave@dave ~]$ pactl set-sink-port 44  analog-output-headphones
[dave@dave ~]$ pactl list sinks |& grep -E "Sink|Ports|analog-ou"
Sink #44
        media.class = "Audio/Sink"
    Ports:
        analog-output-speaker: Speakers (type: Speaker, priority: 10000, availability group: Legacy 3, availability unknown)
        analog-output-headphones: Headphones (type: Headphones, priority: 9900, availability group: Legacy 2, availability unknown)
    Active Port: analog-output-headphones
[dave@dave ~]$ pactl set-sink-port 44  analog-output-headphones

Thursday, December 23, 2021

HP Fortify scan - exclude files

 HOWTO

 

 

 


-exclude

 

Removes files from the list of files to translate. Separate multiple file

<file_specifiers>

 

paths with semicolons (Windows) or colons (non-Windows systems).

 

 

See "Specifying Files and Directories" on page 125 for more

 

 

information on how to use file specifiers.

 

 

For example:

 

 

 

 

 

 

sourceanalyzer –cp "**/*.jar" "**/*"

 

 

 

-exclude "**/Test/*.java"

 

 

 

 

 

 

 

This example excludes all Java files in any Test subdirectory.

 

 

 

 

 

Note: When you integrate the translation with a compiler or a

 

 

 

build tool, Fortify Static Code Analyzer translates all source files

 

 

 

that the compiler or build tool processes even if they are specified

 

 

 

with this option.

 

 

 

 

 

 

 

Equivalent Property Name:

 

 

com.fortify.sca.exclude

 

 

 

Specifying Files and Directories

File specifiers are expressions that allow you to pass a long list of files or a directory to Fortify Static Code Analyzer using wildcard characters. Fortify Static Code Analyzer recognizes two types of wildcard characters: a single asterisk character (*) matches part of a file name, and double asterisk characters (**) recursively matches directories. You can specify one or more files, one or more file specifiers, or a combination of files and file specifiers.

<files> | <file_dir_specifiers>

Note: File specifiers do not apply to C, C++, or Objective-C++.

The following table describes examples of file and directory specifiers.

File / Directory Specifier

Description

 

 

<dir>

Matches all files in the named directory and any subdirectories

<dir>/**/*

or the named directory when used for a directory parameter.

 

 

 

<dir>/**/Example.java

Matches any file named Example.java found in the named

 

directory or any subdirectories.

 

 

<dir>/*.java

Matches any file with the specified extension found in the

<dir>/*.jar

named directory.

 

 

 

<dir>/**/*.kt

Matches any file with the specified extension found in the

<dir>/**/*.jar

named directory or any subdirectories.

 

 

 

<dir>/**/beta/**

Matches all directories and files found in the named directory

 

that have beta in the path, including beta as a file name.

 

 

<dir>/**/classes/

Matches all directories and files with the name classes found

 

in the named directory and any subdirectories.

 

 

**/test/**

Matches all files in the current directory tree that have a test

 

element in the path, including test as a file name.

 

 

**/webgoat/*

Matches all files in any webgoat directory in the current

 

directory tree.

 

Matches:

 

• /src/main/java/org/owasp/webgoat

 

 

 

Wednesday, December 22, 2021

Refactor log4j project to slf4j

HOWTO 

 

Create simple Java project using Maven archetype

$     mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4

Define value for property 'groupId': : dave
Define value for property 'artifactId': : simple
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  dave: : 
Confirm properties configuration:
groupId: dave
artifactId: simple
version: 1.0-SNAPSHOT
package: dave
 Y: : Y 
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: maven-archetype-quickstart:1.4
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: simple
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: dave
[INFO] Parameter: packageInPathFormat, Value: dave
[INFO] Parameter: package, Value: dave
[INFO] Parameter: groupId, Value: dave
[INFO] Parameter: artifactId, Value: simple
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Archetype in dir: /git/simple/simple
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  36.314 s
[INFO] Finished at: 2021-12-22T22:03:21+01:00
[INFO] ------------------------------------------------------------------------
[dave@dave simple]$ find
.
./simple
./simple/pom.xml
./simple/src
./simple/src/main
./simple/src/main/java
./simple/src/main/java/dave
./simple/src/main/java/dave/App.java
./simple/src/test
./simple/src/test/java
./simple/src/test/java/dave
./simple/src/test/java/dave/AppTest.java
[dave@dave simple]$ 

Add log4j Maven dependency
  <!-- https://mvnrepository.com/artifact/log4j/log4j -->
   <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
   </dependency>

Add log4j 1.2 call
package dave;

// Import log4j classes.
import org.apache.log4j.*;

/**
 * Hello world!
 *
 */
public class App
{
    public static void main( String[] args )
    {

   // get a logger instance named "com.foo"
   Logger  logger = Logger.getLogger("com.foo");

   Logger barlogger = Logger.getLogger("com.foo.Bar");

   // This request is enabled, because WARN >= INFO.
   logger.warn("Low fuel level.");

   // This request is disabled, because DEBUG < INFO.
   logger.debug("Starting search for nearest gas station.");

   // The logger instance barlogger, named "com.foo.Bar",
   // will inherit its level from the logger named
   // "com.foo" Thus, the following request is enabled
   // because INFO >= INFO.
   barlogger.info("Located nearest gas station.");

   // This request is disabled, because DEBUG < INFO.
   barlogger.debug("Exiting gas station search");
    }

}

Add rewrite plugin
      <plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>4.14.1</version>
        <configuration>
          <activeRecipes>
            <recipe>org.openrewrite.java.logging.slf4j.Log4jToSlf4j</recipe>
          </activeRecipes>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.openrewrite.recipe</groupId>
            <artifactId>rewrite-logging-frameworks</artifactId>
            <version>0.9.0</version>
          </dependency>
        </dependencies>
      </plugin>

Discover
[INFO] Available Recipes:
[INFO]                 org.openrewrite.DeleteSourceFiles
[INFO]                 org.openrewrite.FindSourceFiles
[INFO]                 org.openrewrite.RenameFile
[INFO]                 org.openrewrite.hcl.format.AutoFormat
[INFO]                 org.openrewrite.hcl.format.NormalizeFormat
[INFO]                 org.openrewrite.hcl.format.RemoveTrailingWhitespace
[INFO]                 org.openrewrite.hcl.format.Spaces
[INFO]                 org.openrewrite.hcl.format.TabsAndIndents
[INFO]                 org.openrewrite.java.AddLicenseHeader
[INFO]                 org.openrewrite.java.ChangeMethodAccessLevel
[INFO]                 org.openrewrite.java.ChangeMethodName
[INFO]                 org.openrewrite.java.ChangeMethodTargetToStatic
[INFO]                 org.openrewrite.java.ChangeMethodTargetToVariable
[INFO]                 org.openrewrite.java.ChangePackage
[INFO]                 org.openrewrite.java.ChangeType
[INFO]                 org.openrewrite.java.DeleteMethodArgument
[INFO]                 org.openrewrite.java.GenerateGetter
[INFO]                 org.openrewrite.java.NoStaticImport
[INFO]                 org.openrewrite.java.OrderImports
[INFO]                 org.openrewrite.java.RemoveAnnotation
[INFO]                 org.openrewrite.java.RemoveUnusedImports
[INFO]                 org.openrewrite.java.ReorderMethodArguments
[INFO]                 org.openrewrite.java.SimplifyMethodChain
[INFO]                 org.openrewrite.java.UseStaticImport
[INFO]                 org.openrewrite.java.cleanup.AtomicPrimitiveEqualsUsesGet
[INFO]                 org.openrewrite.java.cleanup.BigDecimalRoundingConstantsToEnums
[INFO]                 org.openrewrite.java.cleanup.BooleanChecksNotInverted
[INFO]                 org.openrewrite.java.cleanup.CaseInsensitiveComparisonsDoNotChangeCase
[INFO]                 org.openrewrite.java.cleanup.CatchClauseOnlyRethrows
[INFO]                 org.openrewrite.java.cleanup.ControlFlowIndentation
[INFO]                 org.openrewrite.java.cleanup.CovariantEquals
[INFO]                 org.openrewrite.java.cleanup.DefaultComesLast
[INFO]                 org.openrewrite.java.cleanup.EmptyBlock
[INFO]                 org.openrewrite.java.cleanup.EqualsAvoidsNull
[INFO]                 org.openrewrite.java.cleanup.ExplicitInitialization
[INFO]                 org.openrewrite.java.cleanup.ExplicitLambdaArgumentTypes
[INFO]                 org.openrewrite.java.cleanup.ExternalizableHasNoArgsConstructor
[INFO]                 org.openrewrite.java.cleanup.FallThrough
[INFO]                 org.openrewrite.java.cleanup.FinalClass
[INFO]                 org.openrewrite.java.cleanup.FinalizeLocalVariables
[INFO]                 org.openrewrite.java.cleanup.FixSerializableFields
[INFO]                 org.openrewrite.java.cleanup.ForLoopControlVariablePostfixOperators
[INFO]                 org.openrewrite.java.cleanup.ForLoopIncrementInUpdate
[INFO]                 org.openrewrite.java.cleanup.HiddenField
[INFO]                 org.openrewrite.java.cleanup.HideUtilityClassConstructor
[INFO]                 org.openrewrite.java.cleanup.IndexOfChecksShouldUseAStartPosition
[INFO]                 org.openrewrite.java.cleanup.IndexOfReplaceableByContains
[INFO]                 org.openrewrite.java.cleanup.IndexOfShouldNotCompareGreaterThanZero
[INFO]                 org.openrewrite.java.cleanup.IsEmptyCallOnCollections
[INFO]                 org.openrewrite.java.cleanup.LambdaBlockToExpression
[INFO]                 org.openrewrite.java.cleanup.MethodNameCasing
[INFO]                 org.openrewrite.java.cleanup.MethodParamPad
[INFO]                 org.openrewrite.java.cleanup.MinimumSwitchCases
[INFO]                 org.openrewrite.java.cleanup.MissingOverrideAnnotation
[INFO]                 org.openrewrite.java.cleanup.ModifierOrder
[INFO]                 org.openrewrite.java.cleanup.MultipleVariableDeclarations
[INFO]                 org.openrewrite.java.cleanup.NeedBraces
[INFO]                 org.openrewrite.java.cleanup.NestedEnumsAreNotStatic
[INFO]                 org.openrewrite.java.cleanup.NewStringBuilderBufferWithCharArgument
[INFO]                 org.openrewrite.java.cleanup.NoDoubleBraceInitialization
[INFO]                 org.openrewrite.java.cleanup.NoEmptyCollectionWithRawType
[INFO]                 org.openrewrite.java.cleanup.NoEqualityInForCondition
[INFO]                 org.openrewrite.java.cleanup.NoFinalizer
[INFO]                 org.openrewrite.java.cleanup.NoRedundantJumpStatements
[INFO]                 org.openrewrite.java.cleanup.NoToStringOnStringType
[INFO]                 org.openrewrite.java.cleanup.NoValueOfOnStringType
[INFO]                 org.openrewrite.java.cleanup.NoWhitespaceAfter
[INFO]                 org.openrewrite.java.cleanup.NoWhitespaceBefore
[INFO]                 org.openrewrite.java.cleanup.OperatorWrap
[INFO]                 org.openrewrite.java.cleanup.PadEmptyForLoopComponents
[INFO]                 org.openrewrite.java.cleanup.PrimitiveWrapperClassConstructorToValueOf
[INFO]                 org.openrewrite.java.cleanup.RedundantFileCreation
[INFO]                 org.openrewrite.java.cleanup.RemoveExtraSemicolons
[INFO]                 org.openrewrite.java.cleanup.RemoveUnusedLocalVariables
[INFO]                 org.openrewrite.java.cleanup.RemoveUnusedPrivateMethods
[INFO]                 org.openrewrite.java.cleanup.RenameLocalVariablesToCamelCase
[INFO]                 org.openrewrite.java.cleanup.RenameMethodsNamedHashcodeEqualOrTostring
[INFO]                 org.openrewrite.java.cleanup.SimplifyBooleanExpression
[INFO]                 org.openrewrite.java.cleanup.SimplifyBooleanReturn
[INFO]                 org.openrewrite.java.cleanup.StaticMethodNotFinal
[INFO]                 org.openrewrite.java.cleanup.StringLiteralEquality
[INFO]                 org.openrewrite.java.cleanup.TypecastParenPad
[INFO]                 org.openrewrite.java.cleanup.UnnecessaryCloseInTryWithResources
[INFO]                 org.openrewrite.java.cleanup.UnnecessaryExplicitTypeArguments
[INFO]                 org.openrewrite.java.cleanup.UnnecessaryParentheses
[INFO]                 org.openrewrite.java.cleanup.UnnecessaryPrimitiveAnnotations
[INFO]                 org.openrewrite.java.cleanup.UnnecessaryThrows
[INFO]                 org.openrewrite.java.cleanup.UseCollectionInterfaces
[INFO]                 org.openrewrite.java.cleanup.UseDiamondOperator
[INFO]                 org.openrewrite.java.cleanup.UseFilesCreateTempDirectory
[INFO]                 org.openrewrite.java.cleanup.UseJavaStyleArrayDeclarations
[INFO]                 org.openrewrite.java.cleanup.UseLambdaForFunctionalInterface
[INFO]                 org.openrewrite.java.cleanup.WhileInsteadOfFor
[INFO]                 org.openrewrite.java.cleanup.WriteOctalValuesAsDecimal
[INFO]                 org.openrewrite.java.format.AutoFormat
[INFO]                 org.openrewrite.java.format.BlankLines
[INFO]                 org.openrewrite.java.format.EmptyNewlineAtEndOfFile
[INFO]                 org.openrewrite.java.format.NormalizeFormat
[INFO]                 org.openrewrite.java.format.NormalizeLineBreaks
[INFO]                 org.openrewrite.java.format.NormalizeTabsOrSpaces
[INFO]                 org.openrewrite.java.format.RemoveTrailingWhitespace
[INFO]                 org.openrewrite.java.format.SingleLineComments
[INFO]                 org.openrewrite.java.format.Spaces
[INFO]                 org.openrewrite.java.format.TabsAndIndents
[INFO]                 org.openrewrite.java.format.WrappingAndBraces
[INFO]                 org.openrewrite.java.logging.PrintStackTraceToLogError
[INFO]                 org.openrewrite.java.logging.log4j.PrependRandomName
[INFO]                 org.openrewrite.java.logging.logback.Log4jAppenderToLogback
[INFO]                 org.openrewrite.java.logging.logback.Log4jLayoutToLogback
[INFO]                 org.openrewrite.java.logging.slf4j.Log4jToSlf4j
[INFO]                 org.openrewrite.java.logging.slf4j.ParameterizedLogging
[INFO]                 org.openrewrite.java.search.FindAnnotations
[INFO]                 org.openrewrite.java.search.FindDeprecatedClasses
[INFO]                 org.openrewrite.java.search.FindDeprecatedFields
[INFO]                 org.openrewrite.java.search.FindDeprecatedMethods
[INFO]                 org.openrewrite.java.search.FindDeprecatedUses
[INFO]                 org.openrewrite.java.search.FindEmptyClasses
[INFO]                 org.openrewrite.java.search.FindFields
[INFO]                 org.openrewrite.java.search.FindFieldsOfType
[INFO]                 org.openrewrite.java.search.FindMethods
[INFO]                 org.openrewrite.java.search.FindMissingTypes
[INFO]                 org.openrewrite.java.search.FindText
[INFO]                 org.openrewrite.java.search.FindTypes
[INFO]                 org.openrewrite.java.search.ResultOfMethodCallIgnored
[INFO]                 org.openrewrite.json.ChangeKey
[INFO]                 org.openrewrite.json.ChangeValue
[INFO]                 org.openrewrite.json.DeleteKey
[INFO]                 org.openrewrite.json.search.FindKey
[INFO]                 org.openrewrite.maven.AddDependency
[INFO]                 org.openrewrite.maven.AddPlugin
[INFO]                 org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId
[INFO]                 org.openrewrite.maven.ChangeDependencyScope
[INFO]                 org.openrewrite.maven.ChangePropertyValue
[INFO]                 org.openrewrite.maven.ExcludeDependency
[INFO]                 org.openrewrite.maven.ManageDependencies
[INFO]                 org.openrewrite.maven.OrderPomElements
[INFO]                 org.openrewrite.maven.RemoveDependency
[INFO]                 org.openrewrite.maven.RemoveExclusion
[INFO]                 org.openrewrite.maven.RemovePlugin
[INFO]                 org.openrewrite.maven.RemoveProperty
[INFO]                 org.openrewrite.maven.RemoveRedundantDependencyVersions
[INFO]                 org.openrewrite.maven.UpgradeDependencyVersion
[INFO]                 org.openrewrite.maven.UpgradeParentVersion
[INFO]                 org.openrewrite.maven.UpgradePluginVersion
[INFO]                 org.openrewrite.maven.search.DependencyInsight
[INFO]                 org.openrewrite.maven.search.FindDependency
[INFO]                 org.openrewrite.maven.search.FindPlugin
[INFO]                 org.openrewrite.maven.search.FindProperties
[INFO]                 org.openrewrite.properties.ChangePropertyKey
[INFO]                 org.openrewrite.properties.ChangePropertyValue
[INFO]                 org.openrewrite.properties.DeleteProperty
[INFO]                 org.openrewrite.properties.search.FindProperties
[INFO]                 org.openrewrite.text.ChangeText
[INFO]                 org.openrewrite.text.CreateTextFile
[INFO]                 org.openrewrite.xml.AutoFormat
[INFO]                 org.openrewrite.xml.search.FindTags
[INFO]                 org.openrewrite.yaml.ChangeKey
[INFO]                 org.openrewrite.yaml.ChangePropertyKey
[INFO]                 org.openrewrite.yaml.ChangeValue
[INFO]                 org.openrewrite.yaml.CoalesceProperties
[INFO]                 org.openrewrite.yaml.CopyValue
[INFO]                 org.openrewrite.yaml.DeleteKey
[INFO]                 org.openrewrite.yaml.DeleteProperty
[INFO]                 org.openrewrite.yaml.MergeYaml
[INFO]                 org.openrewrite.yaml.cleanup.RemoveUnused
[INFO]                 org.openrewrite.yaml.format.Indents
[INFO]                 org.openrewrite.yaml.search.FindKey
[INFO]                 org.openrewrite.yaml.search.FindProperty
[INFO]                 org.openrewrite.java.logging.logback.Log4jToLogback
[INFO]                 org.openrewrite.java.cleanup.Cleanup
[INFO]                 org.openrewrite.java.cleanup.CommonStaticAnalysis
[INFO]                 org.openrewrite.java.AddApache2LicenseHeader
[INFO]                 org.openrewrite.java.search.FindSecrets
[INFO] 
[INFO] Available Styles:
[INFO]     com.netflix.genie.Style
[INFO]     org.openrewrite.java.SpringFormat
[INFO]     org.openrewrite.java.GoogleJavaFormat
[INFO]     com.netflix.eureka.Style
[INFO] 
[INFO] Active Styles:
[INFO] 
[INFO] Active Recipes:
[INFO]                 org.openrewrite.java.logging.slf4j.Log4jToSlf4j
[INFO] 
[INFO] Found 173 available recipes and 4 available styles.
[INFO] Configured with 1 active recipes and 1 active styles.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Run rewrite
[dave@dave simple]$ mvn rewrite:run
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------------< dave:simple >-----------------------------
[INFO] Building simple 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> rewrite-maven-plugin:4.14.1:run (default-cli) > process-test-classes @ simple >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ simple ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /git/simple/simple/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ simple ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /git/simple/simple/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ simple ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /git/simple/simple/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ simple ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< rewrite-maven-plugin:4.14.1:run (default-cli) < process-test-classes @ simple <<<
[INFO] 
[INFO] 
[INFO] --- rewrite-maven-plugin:4.14.1:run (default-cli) @ simple ---
[INFO] Using active recipe(s) [org.openrewrite.java.logging.slf4j.Log4jToSlf4j]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Parsing Java main files...
[INFO] Parsing Java test files...
[INFO] Running recipe(s)...
[WARNING] Changes have been made to src/main/java/dave/App.java by:
[WARNING]     org.openrewrite.java.logging.slf4j.Log4jToSlf4j
[WARNING] Please review and commit the results.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

Refactored code - log4j replaced with slf4j
 git diff src/main/java/dave/App.java
diff --git a/src/main/java/dave/App.java b/src/main/java/dave/App.java
index 179d8ff..39a78c9 100644
--- a/src/main/java/dave/App.java
+++ b/src/main/java/dave/App.java
@@ -1,7 +1,9 @@
 package dave;
 
 // Import log4j classes.
-import org.apache.log4j.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Hello world!
@@ -13,14 +15,14 @@ public class App
     {
 
    // get a logger instance named "com.foo"
-   Logger  logger = Logger.getLogger("com.foo");
+   Logger  logger = LoggerFactory.getLogger("com.foo");
 

-   Logger barlogger = Logger.getLogger("com.foo.Bar");
+   Logger barlogger = LoggerFactory.getLogger("com.foo.Bar");
 
    // This request is enabled, because WARN >= INFO.
    logger.warn("Low fuel level.");

package dave;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Hello world!
 *
 */
public class App
{
    public static void main( String[] args )
    {

   // get a logger instance named "com.foo"
   Logger  logger = LoggerFactory.getLogger("com.foo");

   Logger barlogger = LoggerFactory.getLogger("com.foo.Bar");

   // This request is enabled, because WARN >= INFO.
   logger.warn("Low fuel level.");

   // This request is disabled, because DEBUG < INFO.
   logger.debug("Starting search for nearest gas station.");

   // The logger instance barlogger, named "com.foo.Bar",
   // will inherit its level from the logger named
   // "com.foo" Thus, the following request is enabled
   // because INFO >= INFO.
   barlogger.info("Located nearest gas station.");

   // This request is disabled, because DEBUG < INFO.
   barlogger.debug("Exiting gas station search");
    }

}

Wednesday, September 22, 2021

GCP - create VM using Terraform

HOWTO


See  also

Install Terraform 

[dave@dave tmp]$ sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
Adding repo from: https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
[dave@dave tmp]$ sudo dnf -y install terraform
Hashicorp Stable - x86_64                                                                                                                         2.0 MB/s | 602 kB     00:00    
Dependencies resolved.
==================================================================================================================================================================================
 Package                                   Architecture                           Version                                         Repository                                 Size
==================================================================================================================================================================================
Installing:
 terraform                                 x86_64                                 1.0.7-1                                         hashicorp                                  25 M
Installing dependencies:
 openssl                                   x86_64                                 1:1.1.1l-2.fc34                                 updates                                   658 k

Transaction Summary
==================================================================================================================================================================================
Install  2 Packages

Total download size: 26 M
Installed size: 77 M
Downloading Packages:
(1/2): openssl-1.1.1l-2.fc34.x86_64.rpm                                                                                                           1.9 MB/s | 658 kB     00:00    
(2/2): terraform-1.0.7-1.x86_64.rpm                                                                                                               4.3 MB/s |  25 MB     00:05    
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                             4.2 MB/s |  26 MB     00:06     
Hashicorp Stable - x86_64                                                                                                                          10 kB/s | 3.1 kB     00:00    
Importing GPG key 0xA3219F7B:
 Userid     : "HashiCorp Security (HashiCorp Package Signing) <security+packaging@hashicorp.com>"
 Fingerprint: E8A0 32E0 94D8 EB4E A189 D270 DA41 8C88 A321 9F7B
 From       : https://rpm.releases.hashicorp.com/gpg
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                          1/1 
  Installing       : openssl-1:1.1.1l-2.fc34.x86_64                                                                                                                           1/2 
  Installing       : terraform-1.0.7-1.x86_64                                                                                                                                 2/2 
  Running scriptlet: terraform-1.0.7-1.x86_64                                                                                                                                 2/2 
  Verifying        : openssl-1:1.1.1l-2.fc34.x86_64                                                                                                                           1/2 
  Verifying        : terraform-1.0.7-1.x86_64                                                                                                                                 2/2 

Installed:
  openssl-1:1.1.1l-2.fc34.x86_64                                                             terraform-1.0.7-1.x86_64                                                            

Complete!

Create GCP project and Account Key

 https://cloud.google.com/iam/docs/creating-managing-service-account-keys

 

Install gcloud

[dave@dave ~]$ sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el8-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM

[dave@dave ~]$ sudo dnf install google-cloud-sdk
Fedora 34 - x86_64 - Updates                                                                                            72 kB/s | 9.7 kB     00:00    
Fedora Modular 34 - x86_64 - Updates                                                                                    46 kB/s | 8.0 kB     00:00    
Google Cloud SDK                                                                                                        11 MB/s |  38 MB     00:03    
Dependencies resolved.
=======================================================================================================================================================
 Package                                 Architecture                  Version                           Repository                               Size
=======================================================================================================================================================
Installing:
 google-cloud-sdk                        x86_64                        358.0.0-1                         google-cloud-sdk                         82 M

Transaction Summary
=======================================================================================================================================================
Install  1 Package

gcloud init
You are logged in as: [ab123@gmail.com].

Pick cloud project to use: 
 [1] dave-terraform
 [2] genial-acronym-295114
 [3] Create a new project
Please enter numeric choice or text value (must exactly match list 
item):  1

Your current project has been set to: [dave-terraform].

Not setting default zone/region (this feature makes it easier to use
[gcloud compute] by setting an appropriate default value for the
--zone and --region flag).
See https://cloud.google.com/compute/docs/gcloud-compute section on how to set
default compute region and zone manually. If you would like [gcloud init] to be
able to do this for you the next time you run it, make sure the
Compute Engine API is enabled for your project on the
https://console.developers.google.com/apis page.

Created a default .boto configuration file at [/home/dave/.boto]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use ab123@gmail.com by default
* Commands will reference project `dave-terraform` by default
Run `gcloud help config` to learn how to change individual settings

This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.

Some things to try next:

* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
[dave@dave ~]$ gcloud version
Google Cloud SDK 358.0.0
alpha 2021.09.17
beta 2021.09.17
bq 2.0.71
core 2021.09.17
gsutil 4.68

show service account keys
gcloud iam service-accounts keys list \
    --iam-account=sa-name@project-id.iam.gserviceaccount.com
Full creation shown here https://danielveselka.blogspot.com/2024/10/create-gcp-vm-via-terraform.html

Monday, June 7, 2021

Deploy Azure function in Java

HOWTO

GitHub

 https://github.com/dveselka/devops-terraform/tree/master/azure/function/az-func

 

Create function using Maven

 

[dave@dave function]$ mvn archetype:generate -DarchetypeGroupId=com.microsoft.azure -DarchetypeArtifactId=azure-functions-archetype -DjavaVersion=11
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:3.1.2:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:3.1.2:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO] 
[INFO] 
[INFO] --- maven-archetype-plugin:3.1.2:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype [com.microsoft.azure:azure-functions-archetype:1.39] found in catalog remote
Downloading from central: https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-functions-archetype/1.39/azure-functions-archetype-1.39.pom
Downloaded from central: https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-functions-archetype/1.39/azure-functions-archetype-1.39.pom (1.8 kB at 38 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-functions-archetype/1.39/azure-functions-archetype-1.39.jar
Downloaded from central: https://repo.maven.apache.org/maven2/com/microsoft/azure/azure-functions-archetype/1.39/azure-functions-archetype-1.39.jar (18 kB at 457 kB/s)
Define value for property 'groupId' (should match expression '[A-Za-z0-9_\-\.]+'): com.dave
[INFO] Using property: groupId = com.dave
Define value for property 'artifactId' (should match expression '[A-Za-z0-9_\-\.]+'): az-func
[INFO] Using property: artifactId = az-func
Define value for property 'version' 1.0-SNAPSHOT: : 
Define value for property 'package' com.dave: : 
[INFO] Using property: appName = $(artifactId)-$(timestamp)
[INFO] Using property: appRegion = westus
[INFO] Using property: appServicePlanName = java-functions-app-service-plan
[INFO] Using property: docker = false
[INFO] Using property: javaVersion = 11
[INFO] Using property: resourceGroup = java-functions-group
[INFO] Using property: trigger = HttpTrigger
Confirm properties configuration:
groupId: com.dave
groupId: com.dave
artifactId: az-func
artifactId: az-func
version: 1.0-SNAPSHOT
package: com.dave
appName: $(artifactId)-$(timestamp)
appRegion: westus
appServicePlanName: java-functions-app-service-plan
docker: false
javaVersion: 11
resourceGroup: java-functions-group
trigger: HttpTrigger
 Y: : 
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: azure-functions-archetype:1.39
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.dave
[INFO] Parameter: artifactId, Value: az-func
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.dave
[INFO] Parameter: packageInPathFormat, Value: com/dave
[INFO] Parameter: resourceGroup, Value: java-functions-group
[INFO] Parameter: package, Value: com.dave
[INFO] Parameter: appName, Value: $(artifactId)-$(timestamp)
[INFO] Parameter: javaVersion, Value: 11
[INFO] Parameter: groupId, Value: com.dave
[INFO] Parameter: artifactId, Value: az-func
[INFO] Parameter: appServicePlanName, Value: java-functions-app-service-plan
[INFO] Parameter: trigger, Value: HttpTrigger
[INFO] Parameter: appRegion, Value: westus
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: docker, Value: false
[INFO] Executing META-INF/archetype-post-generate.groovy post-generation script
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/home/dave/.m2/repository/org/codehaus/groovy/groovy/2.4.16/groovy-2.4.16.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Project created from Archetype in dir: /git/devops-terraform/azure/function/az-func
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  36.355 s
[INFO] Finished at: 2021-06-07T22:04:15+02:00
[INFO] ------------------------------------------------------------------------
[dave@dave function]$ find
.
./az-func
./az-func/host.json
./az-func/pom.xml
./az-func/local.settings.json
./az-func/src
./az-func/src/main
./az-func/src/main/java
./az-func/src/main/java/com
./az-func/src/main/java/com/dave
./az-func/src/main/java/com/dave/Function.java
./az-func/src/test
./az-func/src/test/java
./az-func/src/test/java/com
./az-func/src/test/java/com/dave
./az-func/src/test/java/com/dave/FunctionTest.java
./az-func/src/test/java/com/dave/HttpResponseMessageMock.java
./az-func/.gitignore

Deploy function to Azure

[dave@dave az-func]$ mvn azure-functions:deploy
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.dave:az-func >--------------------------
[INFO] Building Azure Java Functions 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- azure-functions-maven-plugin:1.12.0:deploy (default-cli) @ az-func ---
[WARNING] The POM for com.microsoft.azure.applicationinsights.v2015_05_01:azure-mgmt-insights:jar:1.0.0-beta is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] Set function worker runtime to java.
[INFO] Auth type: OAUTH2
Default subscription: Free Trial(3434343434343434343)
Username: some.name@gmail.com
[INFO] Subscription: Free Trial(3434343434343434343)
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/home/dave/.m2/repository/org/codehaus/groovy/groovy/2.5.11/groovy-2.5.11.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Creating resource group java-functions-group in region westus...
[INFO] Successfully created resource group java-functions-group.
[INFO] Creating app service plan...
[INFO] Successfully created app service plan java-functions-app-service-plan.
[INFO] Creating function app az-func-20210607220415178...
[INFO] Creating application insights...
[INFO] Successfully created the application insights az-func-20210607220415178 for this Function App. You can visit https://ms.portal.azure.com/#@/resource/subscriptions/3434343434343434343/resourceGroups/java-functions-group/providers/microsoft.insights/components/az-func-20210607220415178/overview to view your Application Insights component.
[INFO] Ignoring decoding of null or empty value to:com.azure.resourcemanager.storage.fluent.models.StorageAccountInner
[INFO] Successfully created function app az-func-20210607220415178.
[INFO] Starting deployment...
[INFO] Trying to deploy artifact to az-func-20210607220415178...
[INFO] Successfully deployed the artifact to https://az-func-20210607220415178.azurewebsites.net
[INFO] Deployment done, you may access your resource through https://ms.portal.azure.com/#@/resource/subscriptions/343434343434/resourceGroups/java-functions-group/providers/Microsoft.Web/sites/az-func-20210607220415178
[INFO] Syncing triggers and fetching function information (Attempt 1/3)...
[INFO] Syncing triggers and fetching function information (Attempt 2/3)...
[INFO] HTTP Trigger Urls:
[INFO]      az-func-20210607220415178/HttpExample : https://az-func-20210607220415178.azurewebsites.net/api/httpexample
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:17 min
[INFO] Finished at: 2021-06-07T22:15:06+02:00
[INFO] ------------------------------------------------------------------------

Run function
https://az-func-20210607343434.azurewebsites.net/api/httpexample?name=dave
Azure function in Portal

Sunday, June 6, 2021

Azure CLI - upload file to Azure Storage Account

 HOWTO

 

 

Get Account Key and upload file

[dave@dave azure]$ export ACCOUNT_KEY=`az storage account keys list --account-name davestorageaccounttf  --query [0].value -o tsv`
[dave@dave azure]$ az storage azcopy blob upload -c davecontainer --account-name davestorageaccounttf -s  /tmp/foo.txt  --account-key $ACCOUNT_KEY

Show container
[dave@dave azure]$ az storage container show --account-key  $ACCOUNT_KEY --account-name davestorageaccounttf --name davecontainer
{
  "metadata": {},
  "name": "davecontainer",
  "properties": {
    "contentLength": 0,
    "etag": "\"34343434\"",
    "hasImmutabilityPolicy": false,
    "hasLegalHold": false,
    "lastModified": "2021-06-06T20:44:21+00:00",
    "lease": {
      "duration": null,
      "state": "available",
      "status": "unlocked"
    },
    "publicAccess": "blob"
  }
}

Blob list
dave@dave azure]$ az storage blob list  --account-key  $ACCOUNT_KEY --account-name davestorageaccounttf --container-name davecontainer
This command has been deprecated and will be removed in future release. Use 'az storage fs file list' instead. For more information go to https://github.com/Azure/azure-cli/blob/dev/src/azure-cli/azure/cli/command_modules/storage/docs/ADLS%20Gen2.md
The behavior of this command has been altered by the following extension: storage-preview
[
  {
    "content": null,
    "deleted": false,
    "metadata": {},
    "name": "foo.txt",
    "properties": {
      "Content-CRC64": null,
      "appendBlobCommittedBlockCount": null,
      "blobTier": "Hot",
      "blobTierChangeTime": null,
      "blobTierInferred": true,
      "blobType": "BlockBlob",
      "contentLength": 6,
      "contentRange": null,
      "contentSettings": {
        "cacheControl": null,
        "contentDisposition": null,
        "contentEncoding": null,
        "contentLanguage": null,
        "contentMd5": "4343434==",
        "contentType": "text/plain; charset=utf-8"
      },
      "copy": {
        "completionTime": null,
        "id": null,
        "progress": null,
        "source": null,
        "status": null,
        "statusDescription": null
      },
      "creationTime": "2021-06-06T20:53:16+00:00",
      "deletedTime": null,
      "encryptionKeySha256": null,
      "etag": "0x8D9292D1B7AE62E",
      "lastModified": "2021-06-06T20:53:16+00:00",
      "lease": {
        "duration": null,
        "state": "available",
        "status": "unlocked"
      },
      "pageBlobSequenceNumber": null,
      "remainingRetentionDays": null,
      "serverEncrypted": true
    },
    "snapshot": null
  }
]