org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException in wildfly - deeplearning4j

I am using deeplearning4j with JBOSS wildfly. I have placed all the modules as mentioned below in the classpath:
<module name="org.nd4j.jackson" />
<module name="org.nd4j.nd4j-api" />
<module name="org.nd4j.nd4j-context" />
<module name="org.nd4j.nd4j-common" />
<module name="org.nd4j.nd4j-cuda-92" />
<module name="org.nd4j.nd4j-cuda-92-platform" />
<module name="org.nd4j.nd4j-native" />
<module name="org.nd4j.nd4j-native-api" />
<module name="org.nd4j.nd4j-native-platform" />
<module name="org.bytedeco.javacpp" />
<module name="org.bytedeco.javacpp-presets.cuda" />
<module name="org.bytedeco.javacpp-presets.cuda-platform" />
<module name="org.bytedeco.javacpp-presets.mkl" />
<module name="org.bytedeco.javacpp-presets.openblas" />
<module name="org.bytedeco.javacv" />
<module name="org.datavec.datavec-api" />
<module name="org.deeplearning4j.deeplearning4j-core" />
<module name="org.deeplearning4j.deeplearning4j-nlp" />
<module name="org.deeplearning4j.deeplearning4j-nn" />
I am still getting an exception java.lang.RuntimeException:
org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: Please ensure that you have an nd4j backend on your classpath. Please see: http://nd4j.org/getstarted.html
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5449)
while executing the below line of code, basically where I read the model
org.deeplearning4j.models.embeddings.loader.WordVectorSerializer.readWord2Vec(WordVectorSerializer.java:787)
Any idea what could be going on here?

ND4j uses ServiceLoader to find the backend. In the Wildfly to enable this, in the jboss-deployment-structure.xml mention services="import".
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<dependencies>
<module name="module.name" services="import"/>
</dependencies>
</deployment>
</jboss-deployment-structure>

Related

The element 'Capabilities' in namespace msix Package.appmanifest xml

I have a warning highlighted for the element:
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="localSystemServices" />
<rescap:Capability Name="packagedServices" />
</Capabilities>
With the below detail:
The element 'Capabilities' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' has invalid
child element 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities'. List of possible elements
expected: 'CapabilityChoice' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as
'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10' as well as 'Capability' in
namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/4' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/6' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/7' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/3' as well as 'Capability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/2' as well as 'CustomCapabilityChoice' in namespace
'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'CustomCapability' in namespace
'http://schemas.microsoft.com/appx/manifest/uap/windows10/4' as well as 'Dev....
The Package.appmanifest xml manifest is below:
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:desktop2="http://schemas.microsoft.com/appx/manifest/desktop/windows10/2"
xmlns:desktop6="http://schemas.microsoft.com/appx/manifest/desktop/windows10/6"
IgnorableNamespaces="uap rescap">
<Identity
Name="11d14331-0000-0000-0000-3c2e4cc6d69d"
Publisher="CN=my.name"
Version="1.0.10.0" />
<Properties>
<DisplayName>My Agent</DisplayName>
<PublisherDisplayName>My</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="My Agent"
Description="My Agent."
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
<uap:SplashScreen Image="Images\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<desktop6:Extension Category="windows.service" EntryPoint="Windows.FullTrustApplication" Executable="Agent\Agent.exe">
<desktop6:Service Name="Agent" StartAccount="localSystem" StartupType="auto"/>
</desktop6:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="localSystemServices" />
<rescap:Capability Name="packagedServices" />
</Capabilities>
<Extensions>
<desktop2:Extension Category="windows.firewallRules">
<desktop2:FirewallRules Executable="Agent\Agent.exe">
<desktop2:Rule Direction="in" IPProtocol="TCP" Profile="all"/>
<desktop2:Rule Direction="in" IPProtocol="UDP"
Profile="all"/>
<desktop2:Rule Direction="out"
IPProtocol="TCP"
Profile="all"/>
<desktop2:Rule Direction="out"
IPProtocol="UDP"
Profile="all"/>
</desktop2:FirewallRules>
</desktop2:Extension>
</Extensions>
</Package>

Wildfly Swarm - Resource adapters (IBM wmq.jmsra.rar)

In these moments, I'm trying to configure the IBM wmq.jmsra.rar resource adapter with Wildfly Swarm in a Java project but without success.
Those are the stepts that I've been doing till now:
1) pom.xml (the artifact was installed manually)
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mq</artifactId>
<version>7.5.0.8</version>
<type>rar</type>
</dependency>
2) module.xml for this resource adapter (in src/main/resources/modules/com/ibm/wsmq/main):
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:2.0" name="com.ibm.mq">
<resources>
<resource-root path="." />
<resource-root path="com.ibm.mq.commonservices.jar" />
<resource-root path="com.ibm.mq.connector.jar" />
<resource-root path="com.ibm.mq.headers.jar" />
<resource-root path="com.ibm.mq.jar" />
<resource-root path="com.ibm.mq.jmqi.jar" />
<resource-root path="com.ibm.mq.jmqi.local.jar" />
<resource-root path="com.ibm.mq.jmqi.remote.jar" />
<resource-root path="com.ibm.mq.jmqi.system.jar" />
<resource-root path="com.ibm.mq.jms.admin.jar" />
<resource-root path="com.ibm.mq.pcf.jar" />
<resource-root path="com.ibm.mqjms.jar" />
<resource-root path="com.ibm.msg.client.commonservices.j2se.jar" />
<resource-root path="com.ibm.msg.client.commonservices.jar" />
<resource-root path="com.ibm.msg.client.jms.internal.jar" />
<resource-root path="com.ibm.msg.client.jms.jar" />
<resource-root path="com.ibm.msg.client.matchspace.jar" />
<resource-root path="com.ibm.msg.client.provider.jar" />
<resource-root path="com.ibm.msg.client.ref.jar" />
<resource-root path="com.ibm.msg.client.wmq.common.jar" />
<resource-root path="com.ibm.msg.client.wmq.factories.jar" />
<resource-root path="com.ibm.msg.client.wmq.jar" />
<resource-root path="com.ibm.msg.client.wmq.v6.jar" />
<resource-root path="dhbcore.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.resource.api" />
<module name="javax.jms.api" />
<module name="javax.management.j2ee.api" />
</dependencies>
</module>
Note: In the main folder of this path I copied the mq-7.5.0.8.rar file too.
3) project-stages.yml:
resource-adapters:
resource-adapters:
mq:
archive: mq.rar
transaction-support: XATransaction
connection-definitions:
BSMConnectionFactoryHigh:
class-name: com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl
jndi-name: jms/bsmConnectionFactoryHigh
config-properties:
hostName:
value: tqhr0712.sede.corp.sanpaoloimi.com
queueManager:
value: TQHR0712
port:
value: 1412
channel:
value: CH.BSMA.CONN
transportType:
value: CLIENT
admin-objects:
BSMSendQueueHigh:
class-name: com.ibm.mq.connector.outbound.MQQueueProxy
jndi-name: jms/bsmSendQueueHigh
config-properties:
baseQueueName:
value: QLOCAL.DATAGRAM.WUO.UOS4APPO9
baseQueueManagerName:
value: TQHR0712
deployment:
com.ibm.mq:mq.rar:
Then, when I run the project I get this error:
2018-02-08 10:33:54 INFO <org.jboss.as.server.deployment> <MSC service thread 1-7> WFLYSRV0028: Stopped deployment mq.rar (runtime-name: mq.rar) in 72ms
2018-02-08 10:33:54 INFO <org.jboss.as.controller> <main> WFLYCTL0183: Service status report
WFLYCTL0184: New missing/unsatisfied dependencies:
service jboss.resourceadapters-subsystem (missing) dependents: [service jboss.deployment.unit."mq.rar".CONFIGURE_MODULE]
Someone would be kind to help to fix this problem?
Thank a lot.
I'm glad to tell you that I found how to make the Wildfly Swarm and IBM websphere mq resource adapter integration with success.
These are the steps to follow:
1) Get the wmq.jmsra.rar from IBM (version 8.x)
2) Creating the artifacts for this file like this:
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mq</artifactId>
<version>8.0.0.7</version>
<type>rar</type>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mq</artifactId>
<version>8.0.0.7</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
3) src/main/resources:
a) Create the folder modules.
b) Inside modules folder create com/ibm/mq/main.
c) Inside the main folder copy the resource adapter (the .rar file) and
rename it as mq.rar.
d) Inside main folder create the file module.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:2.0" name="com.ibm.mq">
<resources>
<resource-root path="." />
<resource-root path="com.ibm.mq.connector.jar" />
<resource-root path="com.ibm.mq.headers.jar" />
<resource-root path="com.ibm.mq.jar" />
<resource-root path="com.ibm.mq.jmqi.jar" />
<resource-root path="com.ibm.mq.pcf.jar" />
<resource-root path="com.ibm.mq.jmqi.local.jar" />
<resource-root path="com.ibm.mqjms.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="javax.resource.api" />
<module name="javax.jms.api" />
<module name="javax.management.j2ee.api" />
</dependencies>
</module>
4) project-stages.yml:
swarm:
jca:
archive-validation:
enabled: false
fail-on-warn: false
resource-adapters:
resource-adapters:
mq:
archive: mq.rar
transaction-support: XATransaction
connection-definitions:
ReinoltroConnectionFactory:
class-name: com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl
jndi-name: jms/testConnectionFactory
recovery-username:
recovery-password:
tracking: false
pool-name: MQCONNF
config-properties:
hostName:
value:
queueManager:
value:
port:
value:
channel:
value:
transportType:
value: CLIENT
admin-objects:
testQueue:
class-name: com.ibm.mq.connector.outbound.MQQueueProxy
jndi-name: jms/testQueue
pool-name: MQQUEUENAME
config-properties:
baseQueueName:
value:
baseQueueManagerName:
value:
deployment:
com.ibm:mq.rar:
5) Java code (send message using JMS 2)
#Stateless
#TransactionManagement(TransactionManagementType.CONTAINER)
public class RichiesteServiceImpl {
....
#Inject
#JMSConnectionFactory("java:/jms/reinoltroConnectionFactory")
JMSContext jmsContext;
#Resource(mappedName = "java:/jms/reinoltroBDQueue")
Queue testQueue;
.....
public boolean sendMessage() {
boolean esitoReinoltro = false;
try {
jmsContext.createProducer().send(reinoltroQueue, "Messaggio di prova" );
esitoReinoltro = true;
return esitoReinoltro;
}
catch(Exception e) {
throw new ServiceException(e);
}
}
}
and the job is done.

NLog not logging the exception or any other text

Here is my Nlog.Config code.
<nlog>
<variable name="logFilePath" value="C:\NLog\IDG-${shortdate}.log" />
<targets>
<target name="logfile"
xsi:type="File"
fileName="${logFilePath}"
layout="${longdate} LEVEL=${level:upperCase=true}: ${message}"
keepFileOpen="true" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile" />
<logger name="*" minlevel="Info" writeTo="logfile" />
<logger name="*" minlevel="Warn" writeTo="file"/>
</rules>
</nlog>
and am defining this in my class
private static Logger logger = LogManager.GetCurrentClassLogger();
and then I'm logging the error as:
catch (Exception ex)
{
logger.Error(ex.Message,"test");
}
Can anyone please suggest me if there is any better way to do this, I don't see the file logging in the destined folder.
It seems that you may not be referencing the config section correctly. Try changing your main config file to something like this and remove the Nlog.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="logFilePath" value="C:\temp\output.log" />
<targets>
<target name="logfile"
xsi:type="File"
fileName="${logFilePath}"
layout="${longdate} LEVEL=${level:upperCase=true}: ${message}"
keepFileOpen="true" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile" />
<logger name="*" minlevel="Info" writeTo="logfile" />
<logger name="*" minlevel="Warn" writeTo="file"/>
</rules>
</nlog>
</configuration>

WSO2 ESB - Consume a OAuth2 Service

I'm tying to call an OAuth token service to retrieve the token.
Below is my proxy. This is a simple rest endpoint call which retrieves the token. For testing purpose I'm trying to log the token in the response.
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="sla_proxy_svc_vo2" startOnLoad="true" trace="disable"
transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log level="custom">
<property name="msg" value="*****INITIATING*****" />
</log>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:echo="http://echo.services.core.carbon.wso2.org"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<nstxt:text xmlns:nstxt="http://ws.apache.org/commons/ns/payload">grant_type=client_credentials&client_id=G6Dk_3ZdrXOfPiuctufVq6GfTWoa&client_secret=jxA8NTkEClE5xGUvGvvhVTDyXM4a</nstxt:text>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args />
</payloadFactory>
<log level="custom">
<property name="msg" value="*****BEFORE TOKEN SERVICE CALL*****" />
</log>
<log level="full" />
<property name="HTTP_METHOD" scope="axis2" type="STRING"
value="POST" />
<property name="messageType" scope="axis2" type="STRING"
value="text/plain" />
<property name="ContentType" scope="axis2" type="STRING"
value="text/plain" />
<property name="Accept" scope="axis2" type="STRING"
value="application/json" />
<send>
<endpoint>
<http format="rest" method="post" trace="disable"
uri-template="http://10.236.70.9:8281/token" />
</endpoint>
</send>
</inSequence>
<outSequence>
<log level="custom">
<property name="msg" value="******OUT SEQUENCE*******" />
</log>
<log level="full" />
<send />
</outSequence>
<faultSequence />
</target>
</proxy>
I'm getting the below response when I call.
DEBUG {org.apache.synapse.transport.http.wire} - << "HTTP/1.1 415 Unsupported Media Type[\r][\n]" {org.apache.synapse.transport.http.wire}
DEBUG {org.apache.synapse.transport.http.wire} - << "X-Frame-Options: DENY[\r][\n]" {org.apache.synapse.transport.http.wire}
DEBUG {org.apache.synapse.transport.http.wire} - << "X-XSS-Protection: 1; mode=block[\r][\n]" {org.apache.synapse.transport.http
Will be please if anyone can guide me of I'm doing anything wrong here.
I was able to call the service with the following payload.
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<root>
<grant_type>client_credentials</grant_type>
<client_id>G6Dk_3ZdrXOfPiuctufVq6GfTWoa</client_id>
<client_secret>jxA8NTkEClE5xGUvGvvhVTDyXM4a</client_secret>
</root>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args />
</payloadFactory>
Also had to add the content type as below.
<property name="messageType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded" />
<property name="ContentType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded" />
This worked and retrieved the token.
Here is a template I'm using in a component to set the oAuth token, you could probably adapt it a bit for your case (sounds like you do not need grantType or user credentials)
<?xml version="1.0" encoding="UTF-8"?>
<template name="getToken" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="tokenURL"/>
<parameter name="clientId"/>
<parameter name="clientSecret"/>
<parameter name="grantType"/>
<sequence>
<property description="Base64 crendetials" expression="base64Encode(fn:concat($func:clientId,':',$func:clientSecret))" name="credentials" scope="default" type="STRING"/>
<property description="Authentication" expression="fn:concat('Basic ', get-property('credentials'))" name="Authorization" scope="transport" type="STRING"/>
<header name="Content-Type" scope="transport" value="application/x-www-form-urlencoded"/>
<property name="messageType" scope="axis2" type="STRING" value="application/x-www-form-urlencoded"/>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<property expression="$func:tokenURL" name="uri.var.authUrl" scope="default" type="STRING"/>
<property expression="$func:grantType" name="uri.var.grantType" scope="default" type="STRING"/>
<call blocking="true">
<endpoint>
<http method="post" uri-template="{uri.var.authUrl}?grant_type={uri.var.grantType}"/>
</endpoint>
</call>
<property expression="json-eval($.access_token)" name="OAuth_Token" scope="default" type="STRING"/>
<property action="remove" description="Remove Headers" name="TRANSPORT_HEADERS" scope="axis2"/>
<property description="Authorization" expression="fn:concat('Bearer ',get-property('OAuth_Token'))" name="Authorization" scope="transport" type="STRING"/>
</sequence>
</template>

Why is my windows service not logging anything?

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,
log4net" />
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.serviceModel>
<!-- Redacted -->
</system.serviceModel>
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<file value="logs\" />
<datePattern value="'Proxy_'dd.MM.yyyy'.log'" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="5MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</root>
<category name="Client.log">
<priority value="ALL" />
</category>
</log4net>
<applicationSettings>
<!-- Redacted -->
</applicationSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
I have the above config for my windows service when it's installed, and I'm initializing my logger like so in the Progam.cs file on the service that I'm installing:
static void Main()
{
XmlConfigurator.Configure();
_logger.Debug("ProxyServerService Started.");
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new ProxyServerService()
};
ServiceBase.Run(ServicesToRun);
_logger.Debug("ProxyServerService Terminated.");
}
When I use pretty much the same configuration in an application that communicates with this service it creates a log directory and writes logs to that directory. But when I run the service nothing happens.
Turns out that the reason I couldn't see the logs is because I'd configured the logger the log in the active directory, which is Windows\system32 and windows wouldn't let me do that.
I changed the following line:
<file value="logs\" />
To:
<file value="C:\AppName\logs\" />
And it works fine.

Resources