Spark - Register model objects with Kyro - Caused by: java.lang.IllegalArgumentException: Class is not registered: - apache-spark

I am registering the classes which has business logic and model classes with Kyro in spark . I get the below exception
> Job aborted due to stage failure: Task 14 in stage 1.0 failed 4 times,
> most recent failure: Lost task 14.3 in stage 1.0 (TID 90, **):
> java.lang.IllegalArgumentException: Class is not registered: Object[]
> Note: To register this class use: kryo.register(Object[].class); at
> com.esotericsoftware.kryo.Kryo.getRegistration(Kryo.java:442) at
> com.esotericsoftware.kryo.util.DefaultClassResolver.writeClass(DefaultClassResolver.java:79)
> at com.esotericsoftware.kryo.Kryo.writeClass(Kryo.java:472) at
> com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:565) at
> org.apache.spark.serializer.KryoSerializerInstance.serialize(KryoSerializer.scala:296)
> at
> org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:239)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> at java.lang.Thread.run(Thread.java:745)
>
> Driver stacktrace:
Kyro Registrtor :
public class KyroSerializer implements KryoRegistrator {
#Override
public void registerClasses(Kryo kryo) {
kryo.register(People.class);
kryo.register(Lookup.class);
}
}
Model class:
class people implements Serializable{
private static final long serialVersionUID = 1L; ...... }
public class Lookup implements Serializable{
private static final long serialVersionUID = 1L;
private String code1;
private String code2;
}
Finally my Spark context :
sc.set("spark.kryo.registrator", KyroSerializer.class.getName())

From the exception, it seems that kryo has not registered a class object for Object[] (array whose entries are of type Object). Please try to change your code as follows:
public class KyroSerializer implements KryoRegistrator {
#Override
public void registerClasses(Kryo kryo) {
kryo.register(Object[].class); // add this line to your class
kryo.register(People.class);
kryo.register(Lookup.class);
}
}
In addition, I would register your custom registrator class with spark like this
sc.set("spark.kryo.registrator", KyroSerializer.class.getCanonicalName());
If it works for you, though, then just ignore my last remark.

Related

UnsatisfiedResolutionException - CDI beans from Quarkus extensions

I'm working on a Quarkus Extension. But I have some problems to inject CDI Beans.
In the runtime module I have this class:
#ApplicationScoped
public class CustomRestClientBuilder{
//#Produces - Removed
//#ApplicationScoped - Removed
public RestClientBuilder newBuilder(String url) throws MalformedURLException {
return RestClientBuilder.newBuilder().baseUrl(new URL(url));
}
}
In the deployment module, I have this class:
class RestClientExtensionProcessor {
private static final String FEATURE = "rest-client-extension";
#BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
#BuildStep
public AdditionalBeanBuildItem producer() {
return new AdditionalBeanBuildItem(CustomRestClientBuilder.class);
}
}
And the problem appears in testing classes. I put the Test in Deployment module and it fails (however, in runtime module it works).
public class CustomRestClientBuilderTest {
#Inject
private CustomRestClientBuilder customRest;
#RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
#Test
public void testGreeting() {
IDummyRestClient restClient = customRest.newBuilder("url")
.build(IDummyRestClient.class);
}
}
The error is:
Build failed due to errors
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception:
javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException:
Unsatisfied dependency for type CustomRestClientBuilder and qualifiers [#Default]
I've checked this post before:
Exposing CDI beans from Quarkus extensions
UPDATED
This way is working (adding the class I need for testing). Does it makes sense?
#RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(CustomRestClientBuilder.class,
IDummyRestClient.class));

Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through field 'myAppUserDetailsService';

Spring boot 1.5.3 project with test user-registry on H2 in memory DB
This is the Error Stacktrace
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through field 'myAppUserDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'SMRTUserService': Unsatisfied dependency expressed through field 'userInfoDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SMRTUserDAO': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #2 of URL [file:/C:/temp/SMRT/target/test-classes/data.sql]: ....
Can someone help me to understand the problem? I can't solve this errors.
Test Controller
public class CustomerControllerTest extends AbstractControllerTest {
#Test
#WithMockUser(roles = "ADMIN")
public void testShow() throws Exception {
mockMvc.perform(get("/customer/list")
.contentType(APPLICATION_JSON_UTF8))
.andExpect(status().isOk());
}
}
AbstractControllerTest
#RunWith(SpringRunner.class)
#SpringBootTest(webEnvironment = WebEnvironment.MOCK)
#AutoConfigureMockMvc
public abstract class AbstractControllerTest extends AbstractTest {
#Autowired protected MockMvc mockMvc;
#Autowired private FilterChainProxy filterChainProxy;
#Autowired private WebApplicationContext webApplicationContext;
#Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
this.mockMvc = webAppContextSetup(webApplicationContext)
.dispatchOptions(true)
.addFilters(filterChainProxy).build();
}
}
SecurityConfiguration
#Configuration
#EnableWebSecurity
#EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
#Autowired private SMRTUserService myAppUserDetailsService;
#Autowired private BCryptPasswordEncoder bCryptPasswordEncoder;
#Bean
public BCryptPasswordEncoder passwordEncoder() {
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
return bCryptPasswordEncoder;
}
#Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(myAppUserDetailsService)
.passwordEncoder(bCryptPasswordEncoder);
}
}
SMRTUSerService
#Service
#Slf4j
public class SMRTUserService implements UserDetailsService {
#Autowired private ISMRTUserDAO userInfoDAO;
#Autowired private SMRTUserRepository smrtuserRepository;
...
}
Thanks
Well, your Exception already explains pretty well what the problem is:
Failed to execute SQL script statement #2 of URL [file:/C:/temp/SMRT/target/test-classes/data.sql]: ....
I asume you're importing some test data for your tests? There must be an error in your SQL statements.
if you are using keycloak for the authentification . you might get this error .
jhipster by default gives you 8090 as auth server , so you have to change it
Solution : 1 - start your keycloak server
2 - go to your jhipster project main->ressources->config->application.yml
change issuer ui by the port where your keycloak server is running : for example : issuer-uri: http://localhost:8080/auth/realms/demo
hope that was helpfull

ClassCastException in customComponentcontroller model

I have created my custom ABC component extending the SimpleCMSComponentModel.
It is giving class cast exception in ABCComponentController - > fillModel
java.lang.ClassCastException: de.hybris.platform.cms2.model.contents.components.SimpleCMSComponentModel cannot be cast to ABCComponentController
Any suggestion will be helpfull
You must be forgot to change your custom model from SimpleCMSComponentModel to ABCComponentModel.
This should be like this
#Controller("ABCComponentController")
#Scope("tenant")
#RequestMapping(value = ControllerConstants.Actions.Cms.ABCComponentController)
public class ABCComponentController extends AbstractCMSComponentController<ABCComponentModel>
{
/**
* Fill Model
*/
#Override
protected void fillModel(final HttpServletRequest request, final Model model, final ABCComponentModel component)
{
//
}
}
where
ControllerConstants.Actions.Cms.ABCComponentController = "/view/ABCComponentController"; or your custom path..

PersistenceContextType.EXTENDED leads to failed lookup of Session Bean

I am upgrading from JBoss 7.1.1 to WildFly 8.1.0 and can't get rid of the error described below:
14:53:04,666 ERROR [org.jboss.as.ejb3.invocation] (default task-17) JBAS014134: EJB Invocation failed on component TransRbDAO for method public java.util.List de.bss.dm.kairos.db.kairosgui.TransRbDAO.findAll(): javax.ejb.EJBException: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
TransRbDAO is:
#Stateless
public class TransRbDAO extends AbstractDAO<TransRb> {
public List<TransRb> findAll() {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<TransRb> criteria = cb.createQuery(TransRb.class);
Root<TransRb> root = criteria.from(TransRb.class);
criteria.select(root);
return em.createQuery(criteria).getResultList();
}
}
with AbstractDAO like:
public class AbstractDAO<T> {
#Inject
#CsarGuiDBExtended
#PersistenceContext(unitName = "CSAR_GUI", type = PersistenceContextType.EXTENDED)
protected EntityManager em;
public T findById(Class<T> clazz, Object primaryKey) {
T i = em.find(clazz, primaryKey);
return i;
}
}
This construct works when using only #PersistenceContext(unitName = "CSAR_GUI"), except for the expected LazyInitializationException when accessing data on the JSF-page.
The root-cause for error above is:
Caused by: javax.naming.NamingException: JBAS011878: Failed to lookup env/de.bss.dm.kairos.db.kairosgui.AbstractDAO/em [Root exception is java.lang.ArrayIndexOutOfBoundsException]
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:144)
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:81)
Is this a bug in WildFly? Was this working only because of a bug in JBoss? Or am I doing something completely wrong?
Extended persistence context can only be used in stateful session beans.
See EJB 3.2 spec section 11.11.1.1 or this article:
http://docs.jboss.org/ejb3/app-server/tutorial/extended_pc/extended.html
It appears that the failing code was implemented in JBoss 7.2.0. At this time the setting
default-extended-persistence-inheritance was introduced. Along came the Method
static Map<String, ExtendedEntityManager> More ...getCurrentCall() {
ArrayList<Map<String, ExtendedEntityManager>> stack = currentSFSBCallStack();
Map<String, ExtendedEntityManager> result = null;
if (stack != null) {
result = stack.get(stack.size() - 1);
}
return result;
}
stack.get() was throwing the ArrayIndexOutOfBounds-Exception.
When setting default-extended-persistence-inheritance="DEEP" in standalone.xml and marking TransRbDAO #Stateful the error disappears.
I'm not sure whether it was a bug in JBoss 7.1.1 that I used, or if it is a bug since 7.2.0, clarification is appreciated ;)

Remote EJB call class not found exception

I'm trying to play around with EJB remote call but I'm getting an error. I have a web app called CallerApp that calls a method in another web app called RecieverApp.
In the CallerApp I have a remote interface:
#Remote
public interface ControllerRemote {
public int perform(int i);
}
and the call is performed in this class:
public class Talker {
#EJB private ControllerRemote remote;
//constructor and invoke setRemote() method to set remote
private void setRemote() throws Exception{
Properties p = new Properties();
Context jndiContext = new InitialContext(p);
Object ref = jndiContext.lookup("java:global/RecieverApp/Controller!bean.ControllerRemote");
remote = (ControllerRemote) PortableRemoteObject.narrow(ref, ControllerRemote.class);
}
public void action(){
remote.perform(5);
}
}
RecieverApp is depoloyed on the same Glassfish server:
#Stateless
public class Controller implements Serializable, ControllerRemote{
#Override
public int perform(int i){
//return something
}
}
The interface in RecieverApp is exactly as the one in CallerApp:
#Remote
public interface CallerRemote{
public int perform(int i);
}
I'm getting the following exception:
SEVERE: javax.naming.NamingException: Lookup failed for 'java:global/RecieverApp/Controller!bean.ControllerRemote'
in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
java.naming.factory.url.pkgs=com.sun.enterprise.naming}
[Root exception is javax.naming.NamingException: ejb ref resolution error for remote business interfacebean.ControllerRemote
[Root exception is java.lang.ClassNotFoundException: bean.ControllerRemote]]
What I'm doing wrong here?
PS: I'm using Glassfish 3.1 and both applications are deployed on the same server.
There are few things to consider:
check whether JNDI name java:global/RecieverApp/Controller!bean.ControllerRemote exists, there was nice JNDI browser in Glassfish 2.x, but they didn't put it in GF 3 (it should be in GF 4), but you still have good old command line: asadmin list-jndi-entries
check whether your CallerRemote interfaces are in same packages in both applications
there is no need to perform both injection (#EJB) and JNDI lookup, if your class Talker is container-managed (i.e. bean, servlet, etc.) then #EJB annotation will suffice, otherwise use only lookup

Resources