Java hadoop api YarnClient doesn't have "init()/start()" function? - java

I tried maven repo like this:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-common</artifactId>
<version>2.7.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-yarn-api -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-api</artifactId>
<version>2.7.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-yarn-client -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-client</artifactId>
<version>2.7.2</version>
</dependency>
Then my java code:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.ApplicationConstants;
import org.apache.hadoop.yarn.api.records.*;
import org.apache.hadoop.yarn.client.api.YarnClient;
import org.apache.hadoop.yarn.client.api.YarnClientApplication;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnException;
public static void main(String[] args) {
YarnConfiguration yarnConfiguration = new YarnConfiguration();
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(yarnConfiguration);
yarnClient.start();
}
Intellij ide shows "Cannot solve method init" and "Cannot solve method start".
I then tried to use jar version of 3.1.1 instead of "2.7.2". Same result. So what's wrong with my code and how to fix it?

the init and start method are derived from the AbstractService class.
you need to verify the YarnClient and AbstractService has the same version.
go to YarnClient and check the jar it refer to, then click on the AbstractService parent from the Yarn client and check his version.
change the YarnClient version according to your AbstractService version.
i had the same issue, it works for me . version 2.6.5 .

Related

groovy-eclipse-compiler compiles but javac compilation fails

My project builds successfully with groovy-eclipse-compiler, but fails without groovy-eclipse-compiler (using just javac). The build fails with an error message as given below (reported in a test class, while mocking an invocation)
java: reference to getFileResource is ambiguous
In order to debug the issue, I created a project with minimal files (given below). Though in project we have groovy source also, but I have not included them here to keep the code minimal.
The code is also pushed to git and is available at https://github.com/kaushalkumar/project-debug
My Doubt: The reported issue looks to be legitimate and I feel that groovy-eclipse-compiler must also fail, but it seems that the error is ignored. I am trying to understand what make groovy compiler to ignore it. Is it an issue in groovy compiler?
src/main/java/pkg1/IStrategy.java
package pkg1;
import java.util.Map;
public interface IStrategy {
Map<String, Object> getEnvMap();
}
src/main/java/pkg1/SharedResourceHelper.java
package pkg1;
import java.io.File;
import java.io.IOException;
import java.util.Map;
public class SharedResourceHelper {
public static File getFileResource(final String resourceName, final IStrategy strategy) throws IOException {
return getFileResource(resourceName, strategy.getEnvMap());
}
public static File getFileResource(final String resourceName, final Map<String, Object> envConfig) throws IOException {
return null;
}
}
src/test/java/pkg1/StrategyTest.java
package pkg1;
import pkg1.SharedResourceHelper;
import org.easymock.EasyMock;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.junit.Test;
import org.powermock.modules.junit4.PowerMockRunner;
import org.junit.runner.RunWith;
import java.io.File;
#PrepareForTest({SharedResourceHelper.class})
#RunWith(PowerMockRunner.class)
public class StrategyTest {
#Test
#PrepareForTest({SharedResourceHelper.class})
public void testGetFileResource() throws Exception {
PowerMock.mockStatic(SharedResourceHelper.class);
EasyMock.expect(SharedResourceHelper.getFileResource(EasyMock.anyString(), EasyMock.anyObject())).andReturn(File.createTempFile("tmp", "s"));
// EasyMock.expect(SharedResourceHelper.getFileResource("test", null)).andReturn(File.createTempFile("tmp", "s"));
}
}
/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>project.debug</groupId>
<artifactId>project</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>1.8</source>
<target>1.8</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Java version - 1.8.0_231
Maven - 3.6.2
OS - Mac 10.15.6
groovy-eclipse-compiler - 2.9.2-01
groovy-eclipse-batch - 2.4.3-01
You reference "SharedResourceHelper.getFileResource(EasyMock.anyString(), EasyMock.anyObject())" is indeed ambiguous. If you add a typecast before "EasyMock.anyObject()" you could disambiguate. And EasyMock probably provides an "any" method that you can pass a type into as well.
groovy-eclipse-compiler is based upon ecj (eclipse compiler for java) and not javac, so there are bound to be differences. It may also be that ecj has a different default error/warning level for this particular case. If you feel this should be an error, you can file a JDT bug at bugs.eclipse.org.
eric-milles gave some direction to further explore this. His input is available at https://github.com/groovy/groovy-eclipse/issues/1157.
Based on his comment, we explored the history of https://github.com/groovy/groovy-eclipse/blob/master/extras/groovy-eclipse-batch-builder/build.properties and found that the compilation issue was between 2.4.12-01 (compilation works) and 2.4.12-02 (compilation breaks- as expected), which was part of release 2.9.2.
The change happened on Aug 10, 2017 (13c1c2a#diff-c8c111c3afb6080ae6b32148caaf6a0a), with comment as "Remove codehaus references". The jdt.patch.target was targeted for e44 which is Luna. This was same for both the files.
I invested some time in exploring https://github.com/eclipse/eclipse.jdt.core, to figure out how compiler behaviour could have altered, but could not get much. Though I am not very sure, but I feel that change in groovy-eclipse-batch (between 2.4.12-01 and 2.4.12-02) might be the cause of this.
Having invested this much time, I feel that it is not worth to further debug on this to figure out the root cause as the issue is already fixed in next version(s) [2.4.12-02 and beyond].

POM to import JGraphT nio package

Trying to run the JGraphT hello world example, POM per here looks like:
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.4.0</version>
But this is not pulling down the org.jgrapht.nio.* it seems, file tree below:
What do I need in the POM to do these successfully:
import org.jgrapht.nio.*;
import org.jgrapht.nio.dot.DOTExporter;
Thanks
For me, it works when I add this following dependency :
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-io</artifactId>
<version>1.4.0</version>
</dependency>
in the pom.xml file.
After that, import the dependency in your file of code :
import org.jgrapht.nio.*;

Facing error "cucumber.runtime.CucumberException: No backends were found."

I am working on Selenium with Cucumber setup and I am facing error when I run the TestRunner file.
cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Automation</groupId>
<artifactId>Cucumber</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Cucumber</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</project>
I have mapped feature file to StepDefinition file as shown below
Feature file
Feature: Login Functionality
Scenario: Home page default login
Given User is on Home page
When User logs into application with valid credentials
Then User should be logged into application and landing page should be displayed to user
StepDefinition file
package stepDefenition;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;
#RunWith(Cucumber.class)
public class StepDefenition {
#Given("^User is on Home page$")
public void user_is_on_home_page() throws Throwable {
System.out.println("User is on Home Page");
}
#When("^User logs into application with valid credentials$")
public void user_logs_into_application_with_valid_credentials() throws Throwable {
System.out.println("User enters valid credentials and clicks on submit");
}
#Then("^User should be logged into application and landing page should be displayed to user$")
public void user_should_be_logged_into_application_and_landing_page_should_be_displayed_to_user() throws Throwable {
System.out.println("User logged in successfully and landing page is displayed to user with all the details");
}
}
Test Runner File:
package cucumberOption;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/java/features",
glue="stepDefenition")
public class TestRunner {
}
I am using version:
Neon.3 Release (4.6.3) of Eclipse
Natural 0.7.6 Cucumber plugin
Maven version : Apache Maven 3.6.3
Java Version : java version "1.8.0_241"
structure of the project
I have tried changing versions for java and Junit and adding Io.cucumber dependencies nothing worked.
Added java 1.8 jdk to project build path.
I have viewed all previous threads on this kind of issue.
I did not understand why you using #RunWith annotation in step def class. As cucumber will automatically take care of running it via cucumberRunner, so you can execute your test either from Runner class or via feature files(Scenario level or entire feature file) w/o using any #RunWith annotation. Probably this is the cause of your error here-See below exception:
cucumber.runtime.CucumberException:
Classes annotated with #RunWith(Cucumber.class) must not define any
Step Definition or Hook methods. Their sole purpose is to serve as
an entry point for JUnit. Step Definitions and Hooks should be defined
in their own classes. This allows them to be reused across features.
Offending class: class com.abc.StepDefs.FWFeatureTestSteps (for ex).
Also you need not to have separate junit dependency in pom, only cucumber-junit is enough as long as you want cucumber to get the job done.
Note: Don't mix io.cucumber and info.cukes, use any of them. Mixing both will also cause this very same exception.

sikuli classpath UnsatisfiedLinkError no opencv_core with macosx intellij Junit

I have done previous searches trying to find an answer to this however my attempts failed so far. I think the error is quite simple its just not loading the classes.
I am running MacOSX 10 with intellij. I am using it with Junit Spring and Maven & Junit.
I followed the maven dependencies found mvnrepository.com - sikuli-api 1.2.0 so I was thinking that if the dependencies are added to the pom then all files should be in my class path? So I don't understand why its not working?
This previous answer looks close to mine - but its for windows im on a mac. However by using maven I should not need to add it to the class path?? or am I missing something. This similar unanswered question also looks similar uses mac like mine
POM Dependencies added
<dependency>
<groupId>org.sikuli</groupId>
<artifactId>sikuli-api</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.sikuli</groupId>
<artifactId>sikuli-core</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv</artifactId>
<version>2.4.9-0.9</version>
<classifier>macosx-x86_64</classifier>
</dependency>
<dependency>
<groupId>org.piccolo2d</groupId>
<artifactId>piccolo2d-core</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.piccolo2d</groupId>
<artifactId>piccolo2d-extras</artifactId>
<version>1.3.1</version>
</dependency>
My test
static {
System.setProperty("platform.dependency", "macosx-x86_64");
//System.setProperty("platform.dependency", "1"); // tried this also
}
#Test
public void testOne() throws Exception {
File file = new File(getClass().getClassLoader().getResource("camera_icon.png").getFile());
browse(new URL("http://code.google.com"));
ScreenRegion s = new DesktopScreenRegion();
Target target = new ColorImageTarget(file);
// ** Fails here **
ScreenRegion r = s.find(target);
....
The Error - ClassLoader
I followed the debugger and it fails on the class loader for open_core -- see screenshot
Update
I added the POM classifier per Samuel answer below. I also tried setting the system property. still getting the same error.
Also noticed the following error - I have tried to cut it down as much as possible.
Caused by: java.lang.UnsatisfiedLinkError: /private/var/folders/qp/.../libjniopencv_core.dylib: dlopen(/private/var/....../libjniopencv_core.dylib, 1): Library not loaded: #rpath/libopencv_core.2.4.dylib
Referenced from: /private/var/.......libjniopencv_core.dylib
Reason: no suitable image found. Did find:
/private/va.....77/./libopencv_core.2.4.dylib: malformed mach-o image: load command #12 length (0) too small in /private/var/fo......./libopencv_core.2.4.dylib t java.lang.ClassLoader$NativeLibrary.load(Native Method)
The answer is basically in the README.md file, but I'll spell it out here. You will need to set either the platform.dependency system property to the desired platform, for example, macosx-x86_64, or to true the platform.dependencies one, to get dependencies for all platforms. I'm not sure how we're supposed to set that with JUnit Spring (it should be in the docs), but even that doesn't work with SBT anyway, so to work around these cases we can add the platform-specific dependencies manually. Since you're running on Mac OS X and interested in using OpenCV 2.4.9, adding this additional dependency to your pom.xml file should work:
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv</artifactId>
<version>2.4.9-0.9</version>
<classifier>macosx-x86_64</classifier>
</dependency>
For my work around I install opencv via homebrew. Open terminal and type the following.
brew tap homebrew/science
brew info opencv
brew install opencv
This allowed my POM to be much smaller
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sikuliTest</groupId>
<artifactId>sikuliTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sikuli</groupId>
<artifactId>sikuli-api</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</project>
The test
#Test
public void testOne() throws IOException {
File file = new File(getClass().getClassLoader().getResource("image_to_click.jpeg").getFile());
browse(new URL("http://code.google.com"));
// click image that looks like image_to_click.jpeg
ScreenRegion s = new DesktopScreenRegion(1);
ScreenRegion s1 = s.find(new ImageTarget(file));
Mouse mouse = new DesktopMouse();
mouse.click(s1.getCenter());
// take a screenshot and save it
BufferedImage img = s.capture();
File outputfile = new File("screenshot_image.jpg");
ImageIO.write(img, "jpg", outputfile);
}

Could not Create Services for JIRA

I would like to create a service for JIRA. I'm using atlassian-plugin-sdk-3.8.
I write program in java for that service.. When i'm importing the atlassian api
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.ComponentManager;
ProjectManager pm = ComponentManager.getInstance().getProjectCategories();
After i write it, i use atlas-package command.
But here it shows BUILD-FAILURE
[INFO] Compilation failure
F:\services\module\src\main\java\com\first\module\MyPlugin.java:[9,25] cannot fi
nd symbol
could not parse error message: symbol: class ComponentManager
location: package com.atlassian.jira
F:\services\module\src\main\java\com\first\module\MyPlugin.java:20: cannot find
symbol
ProjectManager pm = ComponentManager.getInstance().getProjectCategories();
^
Whats the reason?
Try one of the following depending on your jira api version:
ProjectManager pm = ComponentManager.getInstance().getProjectManager();
ProjectManager pm = ComponentAccessor.getProjectManager();
For more details look at JIRA api
Add dependecies to your pom.xml:
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<!-- Add dependency on jira-core if you want access to JIRA implementation classes as well as the sanctioned API. -->
<!-- This is not normally recommended, but may be required eg when migrating a plugin originally developed against JIRA 4.x -->
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-core</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
...
</dependencies>

Categories