Categories
discuss

How to connect to Postgresql service inside Docker Swarm?

I have a Docker Swarm cluster setup with 3 servers(1 manager and 2 workers).

I started a Postgresql service using the command below:

docker service create --name postgresql 
  --mount src=pg_data,dst=/var/lib/postgresql/data/pgdata 
  -p 6542:5432 
  -e POSTGRES_USER="user" 
  -e POSTGRES_DB="db" 
  -e POSTGRES_PASSWORD="pass" 
  -e PGDATA=/var/lib/postgresql/data/pgdata 
  --constraint 'node.role == manager' 
  postgres

I also created the data volume previously:

docker volume create pg_data

Now, I have another service that I want to start, which is basically a Java application that I bundled into a Docker image and I want to connect it to the postgresql service. I tried the following combinations for the url:

jdbc:postgresql://172.18.0.1:5432/db (docker_gwbridge)

jdbc:postgresql://172.17.0.1:5432/db (docker0)

jdbc:postgresql://localhost:5432/db

jdbc:postgresql://postgresql:5432/db

Any idea what could work?

Answer

You shall use a swarm overlay network to connect to your database inside swarm mode.

First create the overlay network:

docker network create -d overlay mynet

Then make your postgresql service use this network:

docker service create --name postgresql 
  --mount ... 
  --network mynet 
  postgres

Then, don’t forget to use the same network for your Java application container:

docker service create --name myjavaapp 
  --network mynet 
  myjavaapp

Then you can connect to your postgresql through DNS name like:

jdbc:postgresql://postgresql:5432/db

All service’s containers in the mynet network (you can call it as you want, it’s just a name reference), have DNS entries corresponding to service name. This is easier than having to retrieve container’s IP through docker inspect before launching your java application.

You can even avoid the publish port -p 6542:5432 in your postgresql docker service as your probably don’t want to expose this to others.

You can have a look at the official doc to better understand networks in swarm mode.

This SO QA also talks about overlay network.

Categories
discuss

Selected Options disappear in a multiple drop-down select tag with scroll bar in HTML

I have the following multiple drop down select tag

.Something {
  overflow-x: scroll;
  width: 16%;
}
<select multiple size="5" class="Something">
  <option>Optionfghfghfgdgdffyuujkyujg 1</option>
  <option>Optionfghfghfgdgdffyuujkyujg 1</option>
  <option>Option n fgnfn ghdnghd ngdh 2</option>
  <option>Optionfghfghfgdgdffyuujkyujg 1</option>
  <option>Option n fgnfn ghdnghd ngdh 2</option>
  <option>Option n fgnfn ghdnghd ngdh 2</option>
</select>

So whenever I select an option the text towards the right of it disappears.

Like this

I have such several drop downs in my web portal. I don’t want the option text to disappear. Can this be done using HTML or CSS rather than writing a customized JavaScript code? If so how?

Answer

Horizontal scrolling for <select> elements is buggy in Edge/Chrome, and completely unsupported in Firefox.

A work-around supported all browsers would be to simply wrap it in a <div> and apply some of your CSS there instead:

.Something {
  overflow-x: auto;
  overflow-y: auto;
  width: 20%;
  height: 100px;
}

.Something > select {
  overflow-y: hidden;
}
<div class="Something">
    <select multiple size="6">
      <option>Optionfghfghfgdgdffyuujkyujg 1</option>
      <option>Optionfghfghfgdgdffyuujkyujg 1</option>
      <option>Option n fgnfn ghdnghd ngdh 2</option>
      <option>Optionfghfghfgdgdffyuujkyujg 1</option>
      <option>Option n fgnfn ghdnghd ngdh 2</option>
      <option>Option n fgnfn ghdnghd ngdh 2</option>
    </select>
</div>

Some changes had to be made for this to work. The size attribute of your <select> must match the number of options, and your <div> must have a set height.

Categories
discuss

Upgrade App Engine servlet-api-2.5 to servlet-api-3.1?

With the recent announcement of support for Servlet 3.1, I cannot figure out how to modify the App Engine Standard environment to use 3.1 instead of 2.5 in a non-Maven build.

It seems there is no way to upgrade to 3.1?

https://cloudplatform.googleblog.com/2017/06/Google-App-Engine-standard-now-supports-Java-8.html

Answer

Here is a full example given here: https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/appengine-standard-java8/helloworld

Running procedure is also attached.

For Gradle Users:

For non-maven users, you can use gradle.

In gradle build file, line number 39 denotes: https://github.com/GoogleCloudPlatform/getting-started-java/blob/master/appengine-standard-java8/helloworld/build.gradle#L39

providedCompile 'javax.servlet:javax.servlet-api:3.1.0'

Running locally:

gradle appengineRun

If you do not have gradle installed, you can run using ./gradlew appengineRun.

To use visit: http://localhost:8080/

For Maven Users

In pom.xml, line number 62 to 70 denotes that it is using servlet version 3.1.0: https://github.com/GoogleCloudPlatform/getting-started-java/blob/master/appengine-standard-java8/helloworld/pom.xml#L66

<!-- [START servlet] -->
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
  <type>jar</type>
  <scope>provided</scope>
</dependency>
<!-- [END servlet] -->

Hope it will clarify you.

Categories
discuss

Catching errors from spawned Node.js process

Here is an example where child process error is not fired:

const spawn = require('child_process').spawn;
const childProcess = spawn('tar', ['--wrong-option'], { stdio: 'inherit' });

childProcess.on('error', err => {
    console.error('err: ', err);
});

Why is it so? How can the error (error code in particular) be caught from spawned process?

Answer

error events are only generated when spawning the child itself is causing a problem; for instance, when the executable doesn’t exist.

To catch errors “thrown” by the child process, you should listen for exit events and check the code and signal arguments:

childProcess.on('exit', (code, signal) => {
  if (code) {
    console.error('Child exited with code', code)
  } else if (signal) {
    console.error('Child was killed with signal', signal);
  } else {
    console.log('Child exited okay');
  }
});
Categories
discuss

Gradle could not resolve project :linkedin-sdk

I’m using Androis Studio 3.0 Canary 4. In my project i have the Linkedin-sdk, and it works. I can use it. The only problem is that i recive this message when i search to build Gradle. enter image description here

And because i’cant build it i cannot use the designe editor and the preview.

Here is my build.gradle project:

buildscript {
  repositories {
    jcenter()
    maven { url 'https://maven.google.com' }
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
    classpath 'com.google.gms:google-services:3.0.0'
  }
}

allprojects {
   repositories {
       jcenter()
       maven {
           url 'https://maven.google.com'
       }
   }
}

task clean(type: Delete) {
     delete rootProject.buildDir
}

Build.Gradle Module:App

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
           applicationId "com.cving_team.cving"
           minSdkVersion 19
           targetSdkVersion 26
           versionCode 1
           versionName "1.0"
           testInstrumentationRunner 
           "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {...}
buildTypes {
    sdkTest {
        signingConfig signingConfigs.sdkTest
        debuggable true

    }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
        'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-
        core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

compile project(':retrofit-2.1.0')
compile project(':linkedin-sdk')
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:appcompat-v7:26.0.0-beta2'
compile 'com.android.support:customtabs:26.0.0-beta2'
compile 'com.android.support:design:26.0.0-beta2'
compile 'com.android.support:cardview-v7:26.0.0-beta2'
compile 'com.android.support:recyclerview-v7:26.0.0-beta2'
compile 'com.facebook.android:facebook-android-sdk:4.24.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.mutualmobile.android:cardstack:0.5.2'
compile 'com.google.android.gms:play-services-location:11.0.1'
compile 'com.google.android.gms:play-services-places:11.0.1'
compile 'com.squareup.okhttp3:okhttp:3.7.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
compile 'eu.davidea:flexible-adapter:5.0.0-rc1'
compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

Linkedin-sdk is in settings.gradle to.

include ':app', ':retrofit-2.1.0', ':fabby-sdk-jni', ':linkedin-sdk'

What could be the problem?

UPDATE

I have launched this command from terminal: gradlew tasks, and recive this error:

> Configure project :app
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
Configuration 'androidTestCompile' in project ':app' is deprecated. Use 'androidTestImplementation' instead.
Configuration 'testCompile' in project ':app' is deprecated. Use 'testImplementation' instead.
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)

> Configure project :fabby-sdk-jni
Configuration 'compile' in project ':fabby-sdk-jni' is deprecated. Use 'implementation' instead.
Configuration 'androidTestCompile' in project ':fabby-sdk-jni' is deprecated. Use 'androidTestImplementation' instead.
Configuration 'testCompile' in project ':fabby-sdk-jni' is deprecated. Use 'testImplementation' instead.

> Configure project :linkedin-sdk
Configuration 'compile' in project ':linkedin-sdk' is deprecated. Use 'implementation' instead.
Configuration 'androidTestCompile' in project ':linkedin-sdk' is deprecated. Use 'androidTestImplementation' instead.


FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:testSdkTestUnitTest'.
> Could not resolve all task dependencies for configuration ':app:sdkTestUnitTestRuntimeClasspath'.
   > Could not resolve project :linkedin-sdk.
     Required by:
         project :app
      > Unable to find a matching configuration of project :linkedin-sdk:
          - Configuration 'debugApiElements':
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
              - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=sdkTest}' and found incompatible value 'BuildTypeAttr{name=debug}'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'.
          - Configuration 'debugRuntimeElements':
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
              - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=sdkTest}' and found incompatible value 'BuildTypeAttr{name=debug}'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'.
          - Configuration 'releaseApiElements':
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
              - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=sdkTest}' and found incompatible value 'BuildTypeAttr{name=release}'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'.
          - Configuration 'releaseRuntimeElements':
              - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
              - Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=sdkTest}' and found incompatible value 'BuildTypeAttr{name=release}'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required.
              - Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

SOLVED

Just chenage:

compile project(':linkedin-sdk')

to

compile project(path: ':linkedin-sdk', configuration: 'default')

Answer

I have solved my problem. In build.gradle(Module app) buildTypes must have this structure:

buildTypes {
    debug {}
    releaseApp {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
    releaseSdk {
        signingConfig signingConfigs.sdkTest
        debuggable true
    }
}

and in build.gradle(Module linkedinn-sdk) buildTypes must have same structure. So the new code is:

buildTypes {
    debug {}
    releaseApp  {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    releaseSdk {}
}
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..