This project has retired. For details please refer to its Attic page.
EnvironmentChecker xref
View Javadoc

1   package org.apache.archiva.redback.rest.services.utils;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.archiva.redback.system.check.EnvironmentCheck;
22  import org.apache.commons.lang.time.StopWatch;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  import org.springframework.context.ApplicationContext;
26  import org.springframework.stereotype.Service;
27  
28  import javax.inject.Inject;
29  import java.util.ArrayList;
30  import java.util.Collection;
31  import java.util.List;
32  
33  /**
34   * @author Olivier Lamy
35   * @since 1.4
36   */
37  @Service("environmentChecker#rest")
38  public class EnvironmentChecker
39  {
40  
41      private Logger log = LoggerFactory.getLogger( getClass() );
42  
43  
44      @Inject
45      public EnvironmentChecker( ApplicationContext applicationContext )
46      {
47          Collection<EnvironmentCheck> checkers = applicationContext.getBeansOfType( EnvironmentCheck.class ).values();
48  
49          StopWatch stopWatch = new StopWatch();
50          stopWatch.reset();
51          stopWatch.start();
52  
53          if ( checkers != null )
54          {
55              List<String> violations = new ArrayList<String>();
56  
57              for ( EnvironmentCheck check : checkers )
58              {
59                  check.validateEnvironment( violations );
60              }
61  
62              if ( !violations.isEmpty() )
63              {
64                  StringBuilder msg = new StringBuilder();
65                  msg.append( "EnvironmentCheck Failure.\n" );
66                  msg.append( "======================================================================\n" );
67                  msg.append( " ENVIRONMENT FAILURE !! \n" );
68                  msg.append( "\n" );
69  
70                  for ( String v : violations )
71                  {
72                      msg.append( v ).append( "\n" );
73                  }
74  
75                  msg.append( "\n" );
76                  msg.append( "======================================================================" );
77                  log.error( msg.toString() );
78              }
79          }
80  
81          stopWatch.stop();
82          log.info( "time to execute all EnvironmentCheck: {} ms", stopWatch.getTime() );
83      }
84  }