Friday, April 20, 2018

ping in ubuntu

Issue#1: install ping:
apt-get update
apt-get install iputils-ping
Ref:
https://stackoverflow.com/questions/39901311/docker-ubuntu-bash-ping-command-not-found



Issue#2: ping in ubuntu doesn't show the failed messages:

https://askubuntu.com/questions/278441/how-to-show-failed-ping
Solution:
ping -D -O 8.8.8.8

Thursday, April 12, 2018

REST-Save a representation as a file

@Post
    public void saveNewContent(Representation fr)
    {
    String fileName=(String)getRequest().getAttributes().get("VideoID");
        System.out.println("New Content received");
        try {
            fr.write(new FileOutputStream(new File(path+fileName)));
            System.out.println("New content saved successfully");
            writeInFile("VideoResource: New content saved successfully");
        }
        catch (Exception e) {
            e.printStackTrace();
        }

    }

Wednesday, November 1, 2017

How to execute a shell command/ shell script from java code (+ printing the errors and outputs)?

public String executeShellCommand() throws IOException, DockerCertificateException{

try
        {
           
            String target = new String("sh /var/www/html/Deploy-Script");
            //target = new String("sudo docker images 2>&1");
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec(target);
            proc.waitFor();

            //check to see if there is any error
            StringBuffer output = new StringBuffer();
            BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getErrorStream()));

            //for getting the output of the execution, relace above line with this line:
            //BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));

            String line = "";
            while ((line = reader.readLine())!= null) {
                    output.append(line + "\n");
            }
            System.out.println("### " + output);

            System.out.println("Executed the docker shell script");
        } catch (Throwable t)
        {
            t.printStackTrace();
        }
        String response="success";
        System.out.println("response is set: "+response);
        return response;
    }
}

Friday, October 6, 2017

Docker cheat sheet

1- Build the docker image from Dockerfile
   docker build -t surrogate .

2- list of images:
   docker images

3- Create a docker container/instance and check it:
docker run --name surrogate1 -it -d -p 8080:8080 surrogate
 (first 8080 is host IP, second is container IP)

4- list of created containers:

docker ps

5- remove an image: 
 docker rmi -f imageName

6-remove  a container: 
 docker rm [containerName/ID]

7- stop a container:
 docker stop [containerName]

8- start a container: 
docker start [containerName] 

9- log into the docker instance (f9dcdbcaf0ee is the container ID, taken from previous command):
docker exec -i -t f9dcdbcaf0ee bash

10- Stop all containers
docker stop $(docker ps -a -q)

11-Remove all containers
docker rm $(docker ps -a -q)


12- Push an image to dockerhub:

1)create an image with the name in format of [username/image-name] from Dockerfile:
 docker build -t elahehtj/surrogate .

2)log in via CLI
docker login --username=elahehtj --email=n.tahghigh@gmail.com
Pass: DH69...

3) push your image there

 docker push elahehtj/surrogate

SCP command

If you want to copy a file from one ubuntu machine to the other ubuntu one use this command:

scp -i ./keys/eli-dc.pem segment_1.m4s ubuntu@142.150.208.173:/var/www/html

If you want to copy a file from one ubuntu machine to a windows one use "winSCP" application :)

Monday, June 19, 2017

Maven Installation on Ubuntu

apt-cache search maven

sudo apt-get install maven

mvn -version

REF: https://www.mkyong.com/maven/how-to-install-maven-in-ubuntu/

Tuesday, June 6, 2017

Alfresco- REST API

- Create a workflow using Alfresco, you can follow this youtube video:

              https://www.youtube.com/watch?v=T4UV3E6UIpw

- Test the REST API using curl:
  • List the processes:
  • Start a process:
  • Delete a process:
  • curl -u admin@app.activiti.com:admin -H "content-Type:application/json" -X DELETE http://localhost:8080/activiti-app/api/enterprise/process-instances/5        ==>{InstanceID e.g. 14 or 32}  

-Test the REST API using a java restlet client (the client should be deployed on the same host as Alfresco to avoid CORS issues):


package com.elaheh;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.MediaType;
import org.restlet.resource.ClientResource;
import org.restlet.ext.json.*;
import org.json.*;

public class CacheNodeDepController {

        public static void main(String[] args)
        {
           
            JSONObject jo = new JSONObject();
            try {
                 jo.put("processDefinitionId", "OrchestrationPlan:1:4");
                
            } catch (JSONException ex) {         
            }
           
            String uname="admin@app.activiti.com";
            String pass="admin";
            String Address="http://localhost:8080/activiti-app/api/enterprise/process-instances";
            System.out.println("username is: "+uname);
            System.out.println("password is: "+pass);
            ClientResource clientRes = new ClientResource(Address);
            System.out.println("client created");
            clientRes.setChallengeResponse(ChallengeScheme.HTTP_BASIC, uname, pass);
            System.out.println("challenge Response is set ");
            clientRes.post(new JsonRepresentation(jo), MediaType.APPLICATION_JSON);
        if (clientRes.getStatus().isSuccess())
        System.out.println("GET successful.");
    clientRes.release();
    }
}



community:
https://community.alfresco.com/index.jspa
user: my email
pass: Aa6...