Enterprise Framework

Software Solutions in the Enterprise

Google Cloud switch between multiple accounts project in App Engine

View gcloud configuration:

$ gcloud config list

You should see something like:

[core]
account = your.account@gmail.com
disable_usage_reporting = True
project = myproject-somename-123467

Your active configuration is: [default]

Unset the current cloud project

$ gcloud config unset project

Set the new project.  Your current App Engine name is something like:  my-other-project.appspot.com
Just use the first part without the appspot.com

$ gcloud config set project my-other-project

Run gcloud app deploy now

$ gcloud app deploy

You should see it now say something like

Services to deploy:

descriptor:      [/Users/yourname/Source/Repos/appengine/app.yaml]
source:          [/Users/yourname/Source/Repos/appengine]
target project:  [my-other-project]
target service:  [default]
target version:  [20181218t202435]
target url:      [https://my-other-project.appspot.com]


Do you want to continue (Y/n)?  y

sls deploy error - sh: sls: command not found

Running "sls deploy" generates error.  sh: sls: command not found after running 

sls is a part of the serverless framework.  You can install it by going to:

https://www.npmjs.com/package/serverless

or run the following

npm install -g serverless


Splunk Forwarder Linux Setup

Splunk Forwarder Linux Setup

                      # Get splunk wget -O splunkforwarder-7.2.1-be11b2c46e23-Linux-x86_64.tgz 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=7.2.1&product=universalforwarder&filename=splunkforwarder-7.2.1-be11b2c46e23-Linux-x86_64.tgz&wget=true' sudo tar -xvzf splunkforwarder-7.2.1-be11b2c46e23-Linux-x86_64.tgz -C /opt cd /opt/splunkforwarder/bin # Start splunk forwarder sudo ./splunk start --accept-license sudo ./splunk enable boot-start # Change the default password from changeme sudo ./splunk edit user admin -password newp@$$w0rd -role admin -auth admin:changeme # Add forward server (Where to send data) sudo ./splunk add forward-server YourSplunkServer.com:9997 -auth admin:newp@$$w0rd # Point to directory to monitor sudo ./splunk add monitor /opt/log/www1/ Reference: https://www.splunk.com/en_us/resources/videos/splunk-education-getting-data-in-with-forwarders.html

Brew Update Error: The following directories are not writable by your user:

Error: The following directories are not writable by your user:

/usr/local/include

/usr/local/share/man/man3

/usr/local/share/man/man5

/usr/local/share/man/man7

/usr/local/share/man/man8

You should change the ownership of these directories to your user.

To resolve try:

sudo chown -R $(whoami) /usr/local/include /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 /usr/local/share/man/man8

If that fails, just reinstall brew by going to https://brew.sh/

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"


Swagger Codegen for PHP

First install Java 7 or 8

1 - Set environment variables for java

export JAVA_HOME=$(/usr/libexec/java_home)
or
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

export PATH=${JAVA_HOME}/bin:$PATH

2 - Clone the REPO 

$ git clone https://github.com/swagger-api/swagger-codegen.git

3 - Switch into the directory 

$ cd swagger-codegen

3 - Build the project form code using maven.  Direction for maven on other post.

$ mvn clean package

4 - Generate the client for your endpoint

Replace the below item in < > with your custom values.

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
   -i ../acumatica_client/swagger/swagger_customerschema_17.200.001.json \
   -l php \
   --invoker-package "<RootNamespace>\<CustomNamespace>" \
   --git-user-id "<yourgithubuserid>" \
   --git-repo-id "<yourgithubrepo>" \
   -o ~/Source/Repos/<my_output_folder>

5.  Switch to the output folder from above <my_output_folder>

cd ~/Source/Repos/<my_output_folder>

6.  Make git_push executable so we can push to source control.

chmod +x git_push.sh

7.  Push to source control.

./git_push.sh

7a - git pull origin master --allow-unrelated-histories


8 - Open the newly generated README.md file, copy the text from the Installation & Usage, Composer.json section 

~/Source/Repos/<my_output_folder>/SwaggerClient-php/README.md

9 - Open your PHP client project that you want to use the swagger generated code in and paste the previously copied text from README.md

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/<yourgithubuserid>/<yourgithubrepo>.git"
    }
  ],
  "require": {
    "<yourgithubuserid>/<yourgithubrepo>": "*@dev"
  }
}

11 - Run Composer Install from the PHP Client project to install references

$ composer install

Note you may need to run 

$ composer update --lock

Add a generic called runme.php file and add code from README.md

categorySchemaDeleteById($id);
} catch (Exception $e) {
    echo 'Exception when calling CategorySchemaApi->categorySchemaDeleteById: ', $e->getMessage(), PHP_EOL;
}

?>

and run it
   
$ php runme.php

Mac: Install Maven Command Line

Mac:  Install Maven Command Line

Download Apache Maven (MVN) from

https://maven.apache.org/download.cgi

You should download the binary (Targ.gz or zip) and not source

After you have downloaded it, unzip it by double clicking it or unzip by terminal command (example:)

$ unzip apache-maven-3.6.0-bin.zip

Open terminal if you haven't already and go to the download directory.  We'll move the expanded download file to a new location.

$ cd ~/Downloads

$ mv apache-maven-3.6.0-bin /usr/local/bin/maven

Let's add a maven/bin folder to the path

$ nano .bash_profile

Add the line and save it (control + x)

export PATH=/usr/local/bin/maven/bin:$PATH

Close terminal and reopen


Verify you can access mvn

$ mvn --version

Mac: Set JAVA_HOME

Mac: Set JAVA_HOME

Open Terminal

$ nano ~/.bash_profile


Add the following line:

export JAVA_HOME=$(/usr/libexec/java_home)


Close terminal and reopen

Mac - Brew Install Python - fails with Error: No such file or directory @ dir_chdir - /usr/local/Cellar

Installing python using brew install fails.

$ brew install python

==> Installing dependencies for python: gdbm, openssl, readline, sqlite and xz

==> Installing python dependency: gdbm

==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.1.high_sierra.bottle.tar.gz

Already downloaded: /Users/ramiscaray/Library/Caches/Homebrew/downloads/74ba9ab51669f49dc4dc585e1683648d26858c444e775c8f8b819932df55cf14--gdbm-1.18.1.high_sierra.bottle.tar.gz

Error: No such file or directory @ dir_chdir - /usr/local/Cellar

Warning: Bottle installation failed: building from source.

==> Downloading https://ftp.gnu.org/gnu/gdbm/gdbm-1.18.1.tar.gz

Already downloaded: /Users/ramiscaray/Library/Caches/Homebrew/downloads/c6e5196e3cea2a139cb849d508032f117c6351da5fe84323dc13ad2a0600264a--gdbm-1.18.1.tar.gz

Error: An exception occurred within a child process:

  Errno::EPERM: Operation not permitted @ dir_s_mkdir - /usr/local/Cellar

Trying "brew update", "brew doctor" didn't resolve anything.

Solution:

Reinstall homebrew 

Go to https://brew.sh/

Open terminal and rerun homebrew install

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Retry python homebrew install

$ brew install python

Mac Mongodb Installation


Download MongoDB community server

https://www.mongodb.com/download-center/community


Unzip the file in downloads

mongodb-osx-ssl-x86_64-4.0.4.tgz  => mongodb-osx-ssl-x86_64-4.0.4


Copy the file to the bin directory.  Open Terminal

cd mongodb-osx-ssl-x86_64-4.0.4
cd bin
mkdir /usr/local/bin/mongodb
cp * /usr/local/bin/mongodb
sudo mkdir -p /data/db
sudo chmod 777 /data
sudo chmod 777 /data/db


Add the MondgoDB file path to .bash_profile

$ nano ~/.bash_profile


Add the following line to .bash_profile and save:

   export PATH=/usr/local/bin/mongodb:$PATH
You'll probably need to restart the terminal session for path to be applied.


Start MongoDB by typeing mongod (d is for daemon)

$ mongod


Open a new terminal window and switch to the directory, type mongo

$ mongo


Insert a test record

> db.users.insert({"fullname": "robert amiscaray"})


Install Python 3 by doing brew install python.  Note:  PIP3 will also be installed.

$ brew install python


Install httpie for http helpers

$ sudo -H pip3 install httpie

Mac: Run Elasticsearch and Kibana on Docker

Mac:  Run Elasticsearch and Kibana on Docker


Get Elasticsearch docker image

$ docker pull docker.elastic.co/elasticsearch/elasticsearch:6.4.2

Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html


Run Elasticsearch Docker

$ docker run -d -p 9200:9200 -p 9300:9300 -it -h elasticsearch --name elasticsearch elasticsearch:6.4.2

Open a browser and go to http://localhost:9200 


Get the Kibana docker image

$ docker pull docker.elastic.co/kibana/kibana:6.4.2

Reference:  https://www.elastic.co/guide/en/kibana/current/docker.html


Run Kibana docker

$ docker run -d -p 5601:5601 -h kibana --name kibana --link elasticsearch:elasticsearch kibana:6.4.2

Open a browser and go to http://localhost:5601