View Javadoc

1   package org.apache.continuum.purge.controller;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.continuum.distributed.transport.slave.SlaveBuildAgentTransportClient;
23  import org.apache.continuum.distributed.transport.slave.SlaveBuildAgentTransportService;
24  import org.apache.continuum.model.repository.AbstractPurgeConfiguration;
25  import org.apache.continuum.model.repository.DistributedDirectoryPurgeConfiguration;
26  import org.apache.continuum.purge.executor.ContinuumPurgeExecutorException;
27  import org.apache.maven.continuum.configuration.ConfigurationService;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  import java.net.URL;
32  
33  /**
34   * DirectoryPurgeController
35   *
36   * @author
37   * @plexus.component role="org.apache.continuum.purge.controller.PurgeController" role-hint="purge-distributed-directory"
38   */
39  public class DistributedDirectoryPurgeController
40      implements PurgeController
41  {
42      private static final Logger log = LoggerFactory.getLogger( DistributedDirectoryPurgeController.class );
43  
44      /**
45       * @plexus.requirement
46       */
47      private ConfigurationService configurationService;
48  
49      private SlaveBuildAgentTransportService transportClient;
50  
51      public void doPurge( String path )
52      {
53          log.warn( "doPurge( String ) is not supported for DistributedDirectoryPurgeController" );
54      }
55  
56      public void doPurge( AbstractPurgeConfiguration purgeConfig )
57      {
58          DistributedDirectoryPurgeConfiguration dirPurge = (DistributedDirectoryPurgeConfiguration) purgeConfig;
59          try
60          {
61              transportClient.ping();
62  
63              StringBuilder logMsg = new StringBuilder().append(
64                  "Executing directory purge with the following settings[directoryType=" ).
65                  append( dirPurge.getDirectoryType() ).append( ",daysOlder=" ).
66                  append( dirPurge.getDaysOlder() ).append( ", retentionCount=" ).
67                  append( dirPurge.getRetentionCount() ).append( ", deleteAll=" ).
68                  append( dirPurge.isDeleteAll() ).append( "]" );
69  
70              log.debug( logMsg.toString() );
71  
72              transportClient.executeDirectoryPurge( dirPurge.getDirectoryType(), dirPurge.getDaysOlder(),
73                                                     dirPurge.getRetentionCount(), dirPurge.isDeleteAll() );
74          }
75          catch ( Exception e )
76          {
77              log.error( "Unable to execute purge: " + e.getMessage(), e );
78          }
79      }
80  
81      public void initializeExecutors( AbstractPurgeConfiguration purgeConfig )
82          throws ContinuumPurgeExecutorException
83      {
84          DistributedDirectoryPurgeConfiguration dirPurge = (DistributedDirectoryPurgeConfiguration) purgeConfig;
85  
86          try
87          {
88              transportClient = new SlaveBuildAgentTransportClient( new URL( dirPurge.getBuildAgentUrl() ), "",
89                                                                    configurationService.getSharedSecretPassword() );
90          }
91          catch ( Exception e )
92          {
93              throw new ContinuumPurgeExecutorException( e.getMessage(), e );
94          }
95      }
96  }