Uploaded image for project: 'Dev - Nexus Repo'
  1. Dev - Nexus Repo
  2. NEXUS-21384

Can't script repo cleanup policy after v3.19 release

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Do
    • Affects Version/s: 3.19.0
    • Fix Version/s: None
    • Component/s: Repository, Scripting
    • Labels:
      None

      Description

      After upgrading to v3.19 I get the following error when trying to modify the cleanup policy of a repository with groovy. I've modified the cleanup policy name from a string to an array but it looks like there is an internal issue with the cast from the Groovy collection.

      2019-10-04 11:58:07,872+0000 INFO  [qtp1388878461-46] admin org.sonatype.nexus.repository.manager.internal.RepositoryManagerImpl - Creating repository: docker-hosted -> Configuration{repositoryName='docker-hosted', recipeName='docker-hosted', attributes={cleanup={policyName=[HostedContent]}, docker={forceBasicAuth=true, httpPort=8883, v1Enabled=false}, storage={blobStoreName=default, strictContentTypeValidation=true, writePolicy=ALLOW}}}
      2019-10-04 11:58:07,887+0000 ERROR [qtp1388878461-46] admin org.sonatype.nexus.script.plugin.internal.rest.ScriptResource - Exception in script execution for script named: repo
      javax.script.ScriptException: javax.script.ScriptException: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Set
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:162)
              at org.sonatype.nexus.internal.script.ScriptServiceImpl.eval(ScriptServiceImpl.java:161)
              at org.sonatype.nexus.internal.script.ScriptServiceImpl.eval(ScriptServiceImpl.java:170)
              at org.sonatype.nexus.common.script.ScriptService$eval.call(Unknown Source)
              at org.sonatype.nexus.script.plugin.internal.rest.ScriptResource.run(ScriptResource.groovy:161)
              at org.sonatype.nexus.script.plugin.internal.rest.ScriptResource$$EnhancerByGuice$$12c891b9.CGLIB$run$12(<generated>)
              at org.sonatype.nexus.script.plugin.internal.rest.ScriptResource$$EnhancerByGuice$$12c891b9$$FastClassByGuice$$e6f2ee83.invoke(<generated>)
              at com.google.inject.internal.cglib.proxy.$MethodProxy.invokeSuper(MethodProxy.java:228)
              at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:76)
              at com.palominolabs.metrics.guice.ExceptionMeteredInterceptor.invoke(ExceptionMeteredInterceptor.java:23)
              at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:77)
              at com.palominolabs.metrics.guice.TimedInterceptor.invoke(TimedInterceptor.java:26)
              at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:77)
              at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:55)
              at org.sonatype.nexus.script.plugin.internal.rest.ScriptResource$$EnhancerByGuice$$12c891b9.run(<generated>)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:498)
              at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
              at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:294)
              at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:248)
              at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:235)
              at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)
              at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:209)
              at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:227)
              at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
              at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
              at org.sonatype.nexus.siesta.internal.resteasy.ComponentContainerImpl.service(ComponentContainerImpl.java:106)
              at org.sonatype.nexus.siesta.SiestaServlet.service(SiestaServlet.java:137)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
              at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:286)
              at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:276)
              at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:181)
              at com.google.inject.servlet.DynamicServletPipeline.service(DynamicServletPipeline.java:71)
              at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85)
              at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:112)
              at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
              at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
              at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
              at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
              at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
              at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
              at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
              at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
              at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
              at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
              at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
              at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
              at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
              at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
              at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
              at org.sonatype.nexus.security.SecurityFilter.executeChain(SecurityFilter.java:85)
              at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
              at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
              at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
              at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
              at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
              at org.sonatype.nexus.security.SecurityFilter.doFilterInternal(SecurityFilter.java:101)
              at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
              at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
              at com.sonatype.nexus.licensing.internal.LicensingRedirectFilter.doFilter(LicensingRedirectFilter.java:114)
              at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
              at com.codahale.metrics.servlet.AbstractInstrumentedFilter.doFilter(AbstractInstrumentedFilter.java:112)
              at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
              at org.sonatype.nexus.internal.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:79)
              at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
              at org.sonatype.nexus.internal.web.EnvironmentFilter.doFilter(EnvironmentFilter.java:101)
              at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
              at org.sonatype.nexus.internal.web.HeaderPatternFilter.doFilter(HeaderPatternFilter.java:98)
              at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
              at com.google.inject.servlet.DynamicFilterPipeline.dispatch(DynamicFilterPipeline.java:104)
              at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:135)
              at org.sonatype.nexus.bootstrap.osgi.DelegatingFilter.doFilter(DelegatingFilter.java:73)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1602)
              at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540)
              at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
              at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
              at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
              at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
              at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1700)
              at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
              at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
              at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
              at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
              at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1667)
              at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
              at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
              at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
              at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
              at com.codahale.metrics.jetty9.InstrumentedHandler.handle(InstrumentedHandler.java:239)
              at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:152)
              at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
              at org.eclipse.jetty.server.Server.handle(Server.java:505)
              at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
              at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
              at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
              at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
              at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
              at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
              at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:698)
              at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:804)
              at java.lang.Thread.run(Thread.java:748)
      Caused by: javax.script.ScriptException: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Set
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324)
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:159)
              ... 106 common frames omitted
      Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Set
              at org.sonatype.nexus.cleanup.CleanupConfigurationValidator.addToCleanupPoliciesFromCleanupAttributes(CleanupConfigurationValidator.java:107)
              at org.sonatype.nexus.cleanup.CleanupConfigurationValidator.getCleanupPolicy(CleanupConfigurationValidator.java:96)
              at org.sonatype.nexus.cleanup.CleanupConfigurationValidator.validate(CleanupConfigurationValidator.java:72)
              at org.sonatype.nexus.repository.manager.internal.RepositoryManagerImpl.lambda$2(RepositoryManagerImpl.java:392)
              at java.lang.Iterable.forEach(Iterable.java:75)
              at org.sonatype.nexus.repository.manager.internal.RepositoryManagerImpl.validateConfiguration(RepositoryManagerImpl.java:391)
              at org.sonatype.nexus.repository.manager.internal.RepositoryManagerImpl.create(RepositoryManagerImpl.java:344)
              at org.sonatype.nexus.common.stateguard.MethodInvocationAction.run(MethodInvocationAction.java:39)
              at org.sonatype.nexus.common.stateguard.StateGuard$GuardImpl.run(StateGuard.java:272)
              at org.sonatype.nexus.common.stateguard.GuardedInterceptor.invoke(GuardedInterceptor.java:53)
              at org.sonatype.nexus.script.plugin.internal.provisioning.RepositoryApiImpl.createRepository(RepositoryApiImpl.groovy:514)
              at org.sonatype.nexus.script.plugin.internal.provisioning.RepositoryApiImpl$createRepository.call(Unknown Source)
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
              at Script5.scriptBody(Script5.groovy:18)
              at org.sonatype.nexus.internal.script.groovy.GroovyScriptEngineFactory$ScriptWithCleanup.run(GroovyScriptEngineFactory.java:142)
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:321)
              at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:159)
              at org.sonatype.nexus.internal.script.ScriptServiceImpl.eval(ScriptServiceImpl.java:161)
              at org.sonatype.nexus.internal.script.ScriptServiceImpl.eval(ScriptServiceImpl.java:170)
              at org.sonatype.nexus.common.script.ScriptService$eval.call(Unknown Source)
              at org.sonatype.nexus.script.plugin.internal.rest.ScriptResource.run(ScriptResource.groovy:161)
              at com.palominolabs.metrics.guice.ExceptionMeteredInterceptor.invoke(ExceptionMeteredInterceptor.java:23)
              at com.palominolabs.metrics.guice.TimedInterceptor.invoke(TimedInterceptor.java:26)
              ... 92 common frames omitted
      

      If I remove the cleanup config it works fine.

       

      ---EDIT---

      This is the script I'm running.

      import groovy.json.JsonSlurper
      import groovy.json.JsonOutput
      import org.sonatype.nexus.repository.config.Configuration
      
      def params = new JsonSlurper().parseText(args)
      
      def repo = repository.repositoryManager.get(params.name)
      Configuration conf
      
      if (repo == null) {
        // create
        conf = new Configuration(
          repositoryName: params.name,
          recipeName: params.type,
          online: params.online,
          attributes: params.attributes
        )
        repository.createRepository(conf)}
       else {
        // update
        conf = repo.getConfiguration()
        if (conf.getRecipeName() != params.type) {
          throw new Exception("Tried to change recipe for repo ${params.name} to ${params.type}")
        }
        conf.setOnline(params.online)
        conf.setAttributes(params.attributes)
        repo.stop()
        repo.update(conf)
        repo.start()
      }
      
      

      These are the args I'm passing in.

      {
        "name": "docker-hosted",
        "type": "docker-hosted",
        "online": true,
        "attributes": {
          "docker": {
            "httpPort": 8883,
            "forceBasicAuth": true,
            "v1Enabled": false
          },
          "storage": {
            "blobStoreName": "default",
            "strictContentTypeValidation": true,
            "writePolicy": "ALLOW"
          },
          "cleanup": {
            "policyName": [
              "HostedContent"
            ]
          }
        }
      }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            stevehipwell Steve Hipwell
            Last Updated By:
            Rich Seddon
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Date of First Response:

                tigCommentSecurity.panel-title