/*
 * Copyright (c) 2019 Schibsted Media Group.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.spinnaker.orca.clouddriver.tasks.providers.aws.cloudformation;

import com.netflix.spinnaker.orca.Task;
import com.netflix.spinnaker.orca.TaskResult;
import com.netflix.spinnaker.orca.clouddriver.CloudDriverCacheService;
import com.netflix.spinnaker.orca.clouddriver.tasks.AbstractCloudProviderAwareTask;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CloudFormationForceCacheRefreshTask extends AbstractCloudProviderAwareTask
    implements Task {
  static final String REFRESH_TYPE = "CloudFormation";

  @Autowired CloudDriverCacheService cacheService;

  @Override
  public TaskResult execute(@Nonnull Stage stage) {
    String cloudProvider = getCloudProvider(stage);

    Map<String, Object> data = new HashMap<>();

    String credentials = getCredentials(stage);
    if (credentials != null) {
      data.put("credentials", credentials);
    }

    List<String> regions = (List<String>) stage.getContext().get("regions");
    if (regions != null && !regions.isEmpty()) {
      data.put("region", regions);
    }

    String stackName = (String) stage.getContext().get("stackName");
    if (stackName != null) {
      data.put("stackName", stackName);
    }

    cacheService.forceCacheUpdate(cloudProvider, REFRESH_TYPE, data);

    return TaskResult.SUCCEEDED;
  }
}

@@ -721,22 +721,49 @@
 er.orca.
+OverridableTimeoutRetryable
 Task;%0A
-
 import c
@@ -1078,24 +1078,62 @@
 a.util.Map;%0A
+import java.util.concurrent.TimeUnit;%0A
 import javax
@@ -1380,16 +1380,43 @@
 lements 
+OverridableTimeoutRetryable
 Task %7B%0A 
@@ -1522,16 +1522,146 @@
 rvice;%0A%0A
+  private final long backoffPeriod = TimeUnit.SECONDS.toMillis(10);%0A  private final long timeout = TimeUnit.MINUTES.toMillis(5);%0A%0A
   @Overr
@@ -2328,24 +2328,24 @@
 PE, data);%0A%0A
-
     return T
@@ -2368,11 +2368,155 @@
 DED;%0A  %7D
+%0A%0A  @Override%0A  public long getBackoffPeriod() %7B%0A    return backoffPeriod;%0A  %7D%0A%0A  @Override%0A  public long getTimeout() %7B%0A    return timeout;%0A  %7D
 %0A%7D%0A

Add retries when force cache refreshing (#3200)