+user to see if anyone else can provide guidance.
On Fri, Oct 11, 2019 at 5:31 PM Jitendra kumavat
wrote:
> I have added the plugin and checked my, jar it contains the my service
> registered. Still unable to run my JvmInitializer class.
>
>
> org.apache.maven.plugins
> maven-shade-plugin
> 3.2.1
>
>
>
> shade
>
>
>
>implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
>
>
>
>
>
>
>
> On Fri, Oct 11, 2019 at 2:56 PM Luke Cwik wrote:
>
>> It is a common issue for users build processes to use the Maven shade
>> plugin or jarjar and to lose the META-INF/services files.
>> Can you verify that the jar's you submitted to Dataflow contain the
>> META-INF/services files?
>>
>> See this stackoverflow question
>> https://stackoverflow.com/questions/44365545/apache-beam-unable-to-find-registrar-for-gs
>> for
>> a similar problem for more details.
>>
>>
>> On Fri, Oct 11, 2019 at 2:38 PM Jitendra kumavat
>> wrote:
>>
>>> Hi Luke,
>>>
>>> I added @Autoservice for my custom intializer/processor and i can see
>>> the entries in META-INF/Services folder in my build class. Please see the
>>> attached screenshot. Still while running the dataflow job on google cloud i
>>> can not see the my System.out statements in logs. It is not picking up
>>> the GcmJvmInitializer, i believe so.
>>>
>>>
>>> Steps which i follow to run the job:
>>>
>>> 1. mvn clean install
>>> 2. create dataflow template in gcs bucket using mvn compile command.
>>> 3. run the job using gcloud dataflow jobs
>>>
>>> Can you please tell me what's wrong i am doing here. Thanks.
>>>
>>> Below is my classes structure:
>>>
>>> @AutoService(Processor.class)
>>> @SupportedAnnotationTypes(
>>> "org.springframework.context.annotation.*")
>>> @SupportedSourceVersion(SourceVersion.RELEASE_8)
>>> public class MyProcessor extends AbstractProcessor {
>>> @Override
>>> public boolean process(Set annotations,
>>> RoundEnvironment roundEnv) {
>>> return false;
>>> }
>>> }
>>>
>>>
>>>
>>>
>>> @AutoService(GcmJvmInitializer.class)
>>> public class GcmJvmInitializer implements JvmInitializer {
>>>
>>> @Override
>>> public void onStartup() {
>>> System.out.println("Starting Custom GcmJvmInitializer");
>>> ApplicationContext applicationContext = new
>>> AnnotationConfigApplicationContext(
>>> AppConfig.class);
>>> for (String beanName : applicationContext.getBeanDefinitionNames()) {
>>> System.out.println(beanName);
>>> }
>>> System.out.println("Stopping Custom GcmJvmInitializer");
>>> }
>>>
>>> @Override
>>> public void beforeProcessing(PipelineOptions options) {
>>> System.out.println("Starting Custom GcmJvmInitializer");
>>> ApplicationContext applicationContext = new
>>> AnnotationConfigApplicationContext(
>>> AppConfig.class);
>>> for (String beanName : applicationContext.getBeanDefinitionNames()) {
>>> System.out.println(beanName);
>>> }
>>> System.out.println("Stopping Custom GcmJvmInitializer");
>>> }
>>>
>>> }
>>>
>>>
>>> Thanks,
>>>
>>> Jitendra
>>>
>>>
>>> On Thu, Oct 10, 2019 at 6:35 PM Luke Cwik wrote:
>>>
You shouldn't need to call it before running the pipeline as you are
doing (you can if you want but its not necessary).
Have you created a service META-INF entry for the JvmInitializer you
have created or are using @AutoService?
This is the relevant bit of the documentation[1]. Here is some good
docs for how to use @AutoService[2].
1:
https://github.com/apache/beam/blob/f3ce8669b50837d48ab0d0ee9a1298ce3b5bc61c/sdks/java/core/src/main/java/org/apache/beam/sdk/harness/JvmInitializer.java#L30
2: https://github.com/google/auto/tree/master/service
On Thu, Oct 10, 2019 at 5:29 PM Jitendra kumavat <
jkumavat1...@gmail.com> wrote:
> Hi Luke,
>
> I tried the JvmIntializer.beforeProccssing method to initialize the
> spring application context. But it seems not working.
>
>
> * Below is my class definitions. *
>
> JvmInitializer class with context initialization.
>
> public class GcmJvmInitializer implements JvmInitializer {
> @Override
> public void beforeProcessing(PipelineOptions options){
> System.out.println("Starting Custom GcmJvmInitializer");
> ApplicationContext applicationContext = new
> AnnotationConfigApplicationContext(
> AppConfig.class);
> for (String beanName : applicationContext.getBeanDefinitionNames()) {
> System.out.println(beanName);
> }
> System.out.println("Stopping Custom GcmJvmInitializer");
> }
> }
>
>
> *Appconfig*
>
> @Configuration
> @PropertySource("classpath:gcm.properties")
> @ComponentScan(basePackages = {"com.liveramp.intl.gcm"})
> public class AppConfig {
>
> // B