Apache Spark Mllib Fp-growth Function not found Java - java

I'm new with spark, and I want to use the Fp Growth found in Mllib with java and maven. But I get this error during the compilation:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/cjd/fpgexample/src/main/java/org/fpgexample/FpgTest.java:[25,7] cannot find symbol
symbol: class Function
location: class org.fpgexample.FpgTest
this are the imports and the error line:
package org.fpgexample;
import java.util.Arrays;
import java.util.List;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.mllib.fpm.AssociationRules;
import org.apache.spark.mllib.fpm.FPGrowth;
import org.apache.spark.mllib.fpm.FPGrowthModel;
JavaRDD<List<String>> transactions = data.map( new Function<String, List<String>>() {`
I update the maven compiler to the 3.3 (using JDK 1.7), and spark-core and mllib 2.11 (1.5.1) versions. (with the mllib 2.10 1.4 maven didn't recognize the fpm.AssociationRules).
EDIT: I changed the maven compiler, pom.xml and JDK to 1.8 from 1.7, but the error persist.

You should import the correct package as below:
import org.apache.spark.api.java.function.Function;

Related

How to correctly develop, upload java library with dependencies to Oracle DB and call my Java function from PL\SQL?

I have:
Oracle 19c
java 8 on its machine
What i did:
I write simple class with one method in Java 8.
package <mypackage>;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
import com.networknt.schema.ValidationMessage;
import java.io.IOException;
import java.io.Reader;
import java.sql.Clob;
import java.sql.SQLException;
import java.util.Set;
import java.util.stream.Collectors;
public class <classname> {
<some simple validation function>
}
I compile my project with maven and maven-assembly-plugin to build .jar file with dependencies.
I upload it with loadtool: loadjava -f -r -v -synonym -oracleresolver -resolve -grant <user> -thin -user <credentials> <filename>.jar
There were 0 errors during upload. All uploaded classes (including dependencies) have 'VALID' status in dba_objects table.
I write PL/SQL wrapper over my Java function.
create FUNCTION <funcname>(P_IN_BODY_TEXT CLOB, P_IN_BODY_SCHEMA_TEXT CLOB)
RETURN VARCHAR2
AS LANGUAGE JAVA NAME '<packagename>.<classname>.<funcname>(java.sql.Clob, java.sql.Clob) return java.lang.String';
/
I use this function in my ORDS REST Service.
When doing request to ORDS i am getting this exception:
The request could not be processed because an error occurred whilst attempting to evaluate
the SQL statement associated with this resource.
Please check the SQL statement is correctly formed and executes without error. SQL Error Code: 29532,
Error Message: ORA-29532: Java call terminated by uncaught Java exception:
java.lang.NoClassDefFoundError ORA-06512: at <rest stacktrace that gives me nothing>
Quiestion is:
What is root of this problem? By -synonym flag tool creates synonyms for me, all classes is valid. Do i need some permisions to use java packages liike java.sql that in my class imports? I upload some others open sources java libraries into my Oracle, but they doesn't hava dependencies - is that the problem?
Problem was in slf4j library that throws this exception. slf4j was dependency of library that i used.
Didn't dig the problem, I just pick another labrary with less dependencies and its works.

Native Quarkus with AWS lambda does not build

I am trying to use Quarkus native to build my AWS Lambda.
My setup is:
GraalVM 19.3.0
Java 11
Ubuntu
When I run
docker run -v /home/mypc/dev/java/quarkus/alexa_swear/target/<my project>-1.0-SNAPSHOT-native-image-source-jar:/project:z --user 1000:1000 --rm quay.io/quarkus/ubi-quarkus-native-image:19.2.1 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -jar <my project>-1.0-SNAPSHOT-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:+AddAllCharsets -H:EnableURLProtocols=http -H:-JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace <my project>-1.0-SNAPSHOT-runner
I get the following error:
[alexa_swear-1.0-SNAPSHOT-runner:23] (typeflow): 52,070.99 ms
[alexa_swear-1.0-SNAPSHOT-runner:23] (objects): 25,961.57 ms
[alexa_swear-1.0-SNAPSHOT-runner:23] (features): 803.41 ms
[alexa_swear-1.0-SNAPSHOT-runner:23] analysis: 81,015.48 ms
[alexa_swear-1.0-SNAPSHOT-runner:23] (clinit): 1,277.52 ms
[alexa_swear-1.0-SNAPSHOT-runner:23] universe: 4,416.32 ms
Error: Unsupported features in 5 methods
Detailed message:
Call path from entry point to java.lang.Runtime.traceInstructions(boolean):
at java.lang.Runtime.traceInstructions(Runtime.java)
at com.oracle.svm.reflect.Runtime_traceInstructions_91eaacf084b9d7e2af6dcc0028ee87fea9223b51_77.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.net.www.protocol.http.NTLMAuthenticationProxy.isTrustedSite(NTLMAuthenticationProxy.java:102)
at sun.net.www.protocol.http.HttpURLConnection.getServerAuthentication(HttpURLConnection.java:2481)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1743)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
at io.quarkus.amazon.lambda.runtime.AmazonLambdaRecorder$2.run(AmazonLambdaRecorder.java:171)
at java.lang.Thread.run(Thread.java:748)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0) ... 6 more
Error: Image build request failed with exit status 1
The above error is truncated: the same call stack points to different unsupported methods, such as java.lang.Thread.stop.
My basic understanding is thatio.quarkus.amazon.lambda.runtime.AmazonLambdaRecorder$2.run(AmazonLambdaRecorder.java is referencing to some unsupported methods, such as java.lang.Thread.resume().
I have also tried with Quarkus 19.2.1 unsuccessfully.
The above command was executed by mvn clean install -Pnative -Dnative-image.docker-build=true -e.
Finally I have found the cause of my issue.
In the non-working version of my code, I use a factory of com.amazon.ask.AlexaSkill that is somehow injected in the entry point, as follows:
package io.mirko.lambda;
import com.amazon.ask.AlexaSkill;
import com.amazon.ask.Skills;
import com.amazon.ask.dispatcher.request.handler.HandlerInput;
import com.amazon.ask.dispatcher.request.handler.RequestHandler;
import com.amazon.ask.model.RequestEnvelope;
import com.amazon.ask.model.ResponseEnvelope;
import com.amazon.ask.request.interceptor.GenericRequestInterceptor;
import io.mirko.lambda.handlers.*;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.*;
import java.util.stream.StreamSupport;
public class SkillFactory {
#Inject
Instance<RequestHandler> handlers;
#Produces
#ApplicationScoped
#Named
public AlexaSkill<RequestEnvelope, ResponseEnvelope> createSkill() {
return Skills.standard()
.addRequestHandlers(handlers.stream().toArray(RequestHandler[]::new))
.addRequestInterceptor(new GenericRequestInterceptor<HandlerInput>() {
#Override
public void process(HandlerInput handlerInput) {
System.out.format("Processing %s\n", handlerInput.getRequest());
}
})
// Add your skill id below
//.withSkillId("")
.build();
}
}
...
public class SwearStreamLambda extends SkillStreamHandler {
#Named("swearStream")
public SwearStreamLambda() {
//noinspection unchecked
super((AlexaSkill<RequestEnvelope, ResponseEnvelope>)
getBean(new ParameterizedTypeImpl(AlexaSkill.class, RequestEnvelope.class, ResponseEnvelope.class)));
By removing the SkillFactory class and moving its logic inside SwearStreamLambda class the compilation went well.
Some notes:
The issue is not related to CDI, as it is heavily used throughout the project
The issue is not related to #Produces annotation, which is present in other parts of the project
The issue is not related to javax.enterprise.inject.Instance, as its removal does not solve the issue
All in all, I could not find the root cause of the problem, but I consider my issue solved.
P.S. The original problem is eradicated by building with the following:
mvn clean install -Pnative -Dnative-image.docker-build=true -Dquarkus.native.enable-jni=true
Please see https://github.com/quarkusio/quarkus/issues/6395#issuecomment-570755587.
This does not solve all the problems, as Quarkus reflection has to be configured, but it solves the specific issue.
Just some update for 2022
There is an extension in quarkus which do some configuration already for transitive dependencies: https://github.com/quarkiverse/quarkus-amazon-alex
You need GraalVM and docker installed
I just went to:
https://code.quarkus.io/?b=GRADLE&e=io.quarkiverse.amazonalexa%3Aquarkus-amazon-alexa&extension-search=origin:platform%20alexa
download the zip
overwrite all of my existing project/skill.
small further adaptions to my existing skill as described here: https://quarkus.io/guides/writing-native-applications-tips
gradlew build -x test -Dquarkus.package.type=native -Dquarkus.native.container-build=true
upload functions.zip to AWS Lambda

Jersey client javax.ws.rs.client.Client not found

I have a jersey client. I have the following imports in the client class
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
When I compile the application I get
./src/com/uciext/ws/class2/client/StudentClient.java:3: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Client;
^
How can I fix the issue
EDITED:
This is the error trace
./src/com/uciext/ws/hw2/client/InventoryClient.java:4: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Client;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:5: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.ClientBuilder;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:6: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Entity;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:7: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Invocation;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:8: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.WebTarget;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:9: error: package javax.ws.rs.core does not exist
import javax.ws.rs.core.MediaType;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:10: error: package javax.ws.rs.core does not exist
import javax.ws.rs.core.Response;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:15: error: cannot find symbol
Client client = ClientBuilder.newClient();
^
symbol: class Client
location: class InventoryClient
./src/com/uciext/ws/hw2/client/InventoryClient.java:15: error: cannot find symbol
Client client = ClientBuilder.newClient();
^
symbol: variable ClientBuilder
location: class InventoryClient
./src/com/uciext/ws/hw2/client/InventoryClient.java:16: error: cannot find symbol
WebTarget myResource = client.target("http://127.0.0.1:8080/inventory/rest/catalog");
^
symbol: class WebTarget
location: class InventoryClient
./src/com/uciext/ws/hw2/client/InventoryClient.java:17: error: package Invocation does not exist
Invocation.Builder builder = myResource.request(MediaType.TEXT_PLAIN);
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:17: error: cannot find symbol
Invocation.Builder builder = myResource.request(MediaType.TEXT_PLAIN);
^
symbol: variable MediaType
location: class InventoryClient
12 errors
This is the c.sh. I use jersey 2.2.7. I downloaded jersey 2.2.7 and copied it in my lib folder. Can I have the wrong version of jar.
JAXB_PATH=./lib/jaxb-ri-2.2.7/lib
JAXB_LIB=$JAXB_PATH/jaxb-api.jar:$JAXB_PATH/jaxb-core.jar:$JAXB_PATH/jaxb-impl.jar:$JAXB_PATH/jaxb-jxc.jar:$JAXB_PATH/jaxb-xjc.jar
JAXRS_PATH=./lib/jaxrs-ri/lib
JAXRS_API=./lib/jaxrs-ri/api
JAXRS_LIB=$JAXRS_PATH/jersey-server.jar:$JAXRS_PATH/jersey-common.jar:$JAXRS_PATH/jersey-container-servlet.jar:$JAXRS_PATH/jersey-container-servlet-core.jar:$JAXRS_API/javax.ws.rs-api-2.0.jar
CLASSPATH=$CLASSPATH:./lib/jaxrs-ri/api
CLASSPATH=$CLASSPATH:./lib/jaxb-ri-2.2.7/lib
CLASSPATH=$CLASSPATH:./lib/jaxrs-ri/lib
javac -classpath $JAXB_LIB:$JAXRS_LIB:. -d classes ./src/com/uciext/ws/hw2/util/*.java ./src/com/uciext/ws/hw2/backend/model/*.java ./src/com/uciext/ws/hw2/backend/*.java ./src/com/uciext/ws/hw2/backend/impl/*.java ./src/com/uciext/ws/hw2/service/model/catalog/*.java ./src/com/uciext/ws/hw2/service/model/order/*.java ./src/com/uciext/ws/hw2/service/model/orderconfirm/*.java ./src/com/uciext/ws/hw2/service/*.java ./src/com/uciext/ws/hw2/service/impl/*.java
javac -classpath $JAXB_LIB:$JAXRS_LIB:. -d classes ./src/com/uciext/ws/hw2/client/model/catalog/*.java ./src/com/uciext/ws/hw2/client/model/order/*.java ./src/com/uciext/ws/hw2/client/model/orderconfirm/*.java ./src/com/uciext/ws/hw2/client/*.java
Have you included the dependencies to get the implementation of this package?
If you are using maven this post give the details.
For library version, download libraries from here and follow the following tutorial for adding the required jars. Although the Client class is available in jaxrs-ri\api jar.
You want to grab this zip file and make sure the jaxrs-ri/api/jakarta.ws.rs-api-2.1.6.jar is in your classpath.

Hadoop 2.7 - Simple Java code to create directory in HDFS

All I am trying is to create a directory in HDFS using Java programmatically.
I am getting this error.
Exception in thread "main" java.util.ServiceConfigurationError: org.apache.hadoop.fs.FileSystem: Provider org.apache.hadoop.fs.s3a.S3AFileSystem could not be instantiated
Caused by: java.lang.NoClassDefFoundError: com/amazonaws/AmazonServiceException
Caused by: java.lang.ClassNotFoundException: com.amazonaws.AmazonServiceException
Not sure where all these Amazon S3 came over here. Please help.
Here's the code. This is Hadoop 2.7
package tas.module1;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class JavaClient {
public JavaClient() {
}
public static void main(String[] args) throws IOException {
JavaClient jc = new JavaClient();
Configuration config = new Configuration();
config.addResource(new Path("/usr/local/hadoop-2.7.1/etc/hadoop/core-site.xml"));
config.addResource(new Path("/usr/local/hadoop-2.7.1/etc/hadoop/hdfs-site.xml"));
config.set("fs.hdfs.impl",
org.apache.hadoop.hdfs.DistributedFileSystem.class.getName()
);
config.set("fs.file.impl",
org.apache.hadoop.fs.LocalFileSystem.class.getName()
);
FileSystem dfs = FileSystem.get(config);
String dirName = "TestDirectory";
System.out.println(dfs.getWorkingDirectory() +" this is from /n/n");
Path src = new Path(dfs.getWorkingDirectory()+"/"+dirName);
dfs.mkdirs(src);
System.out.println("created dir");
dfs.close();
}
}
ah, this is a bug fixed a while back in HADOOP-12636, which relates to the java service API and classpaths. Hadoop 2.7.2 enumerates all available filesystem implementation classes in JARs, and fails here due to the transient classpath problems.
If you drop the hadoop-aws JAR from your CP this will go away, or just upgrade to Hadoop 2.7.3
It seems that you are missing some dependency related to the working with S3 file system. In order to work with it, you need to have aws java sdk jars deployed in your cluster. You can download aws-java-sdk from http://sdk-for-java.amazonwebservices.com/latest/aws-java-sdk.zip. Then you need to unzip it, and copy every jar in aws-java-sdk/lib/ and aws-java-sdk/third-party/ to your datanodes.
Another option is to create uber jar and include this dependency directly into your jar through maven:
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.91</version>
</dependency>

Java issue NoClassDefFound javax.xml.soap.SOAPPart

I have been given a java app to modify with the following:
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
But When I run it from cmd it throws the error:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/axis/SOAPP art
It seems to find the other imports without issue. Does 'NoClassDefFound' mean the class itself wasn't found? If so how can I check it is there and replace it if not? (I am using Eclipse)
Update: Okay I have found the class in 'JRE System Library>rt.jar>javax.xml.soap>SOAPPart.class' So if the class is there why do I get the error?
Turns out I needed to choose Export> 'Runnable JAR file' in eclipse instead of 'JAR file'

Categories