You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PropagateErrorsDownloadPolicy.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package org.apache.archiva.policies;
  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. import org.apache.commons.lang.StringUtils;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import org.springframework.stereotype.Service;
  24. import java.io.File;
  25. import java.util.ArrayList;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.Properties;
  29. /**
  30. * PropagateErrorsPolicy - a policy applied on error to determine how to treat the error.
  31. */
  32. @Service( "downloadErrorPolicy#propagate-errors" )
  33. public class PropagateErrorsDownloadPolicy
  34. implements DownloadErrorPolicy
  35. {
  36. private Logger log = LoggerFactory.getLogger( PropagateErrorsDownloadPolicy.class );
  37. /**
  38. * Signifies any error should stop searching for other proxies.
  39. */
  40. public static final String STOP = "stop";
  41. /**
  42. * Propagate errors at the end after all are gathered, if there was no successful download from other proxies.
  43. */
  44. public static final String QUEUE = "queue error";
  45. /**
  46. * Ignore errors and treat as if it were not found.
  47. */
  48. public static final String IGNORE = "ignore";
  49. private List<String> options = new ArrayList<>( 3 );
  50. public PropagateErrorsDownloadPolicy()
  51. {
  52. options.add( STOP );
  53. options.add( QUEUE );
  54. options.add( IGNORE );
  55. }
  56. public boolean applyPolicy( String policySetting, Properties request, File localFile, Exception exception,
  57. Map<String, Exception> previousExceptions )
  58. throws PolicyConfigurationException
  59. {
  60. if ( !options.contains( policySetting ) )
  61. {
  62. // Not a valid code.
  63. throw new PolicyConfigurationException( "Unknown error policy setting [" + policySetting +
  64. "], valid settings are [" + StringUtils.join(
  65. options.iterator(), "," ) + "]" );
  66. }
  67. if ( IGNORE.equals( policySetting ) )
  68. {
  69. // Ignore.
  70. log.debug( "Error policy set to IGNORE." );
  71. return false;
  72. }
  73. String repositoryId = request.getProperty( "remoteRepositoryId" );
  74. if ( STOP.equals( policySetting ) )
  75. {
  76. return true;
  77. }
  78. if ( QUEUE.equals( policySetting ) )
  79. {
  80. previousExceptions.put( repositoryId, exception );
  81. return true;
  82. }
  83. throw new PolicyConfigurationException(
  84. "Unable to process checksum policy of [" + policySetting + "], please file a bug report." );
  85. }
  86. public String getDefaultOption()
  87. {
  88. return QUEUE;
  89. }
  90. public String getId()
  91. {
  92. return "propagate-errors";
  93. }
  94. public String getName()
  95. {
  96. return "On remote error";
  97. }
  98. public List<String> getOptions()
  99. {
  100. return options;
  101. }
  102. }