/*
 * Copyright 2020 Netflix, Inc.
 *
 * 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.echo.scheduler.actions.pipeline;

import com.netflix.spinnaker.kork.discovery.InstanceStatus;
import com.netflix.spinnaker.kork.discovery.RemoteStatusChangedEvent;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.context.ApplicationListener;

@Slf4j
public class QuartzDiscoveryActivator implements ApplicationListener<RemoteStatusChangedEvent> {
  private final Scheduler scheduler;

  public QuartzDiscoveryActivator(Scheduler scheduler) {
    this.scheduler = scheduler;
  }

  @Override
  public void onApplicationEvent(RemoteStatusChangedEvent event) {
    if (event.getSource().getStatus() == InstanceStatus.UP) {
      log.info("Instance is ${e.status}... resuming quartz scheduler");
      try {
        scheduler.start();
      } catch (SchedulerException e) {
        log.warn("Failed to resume quartz scheduler", e);
      }
    } else if (event.getSource().getPreviousStatus() == InstanceStatus.UP) {
      log.info("Instance is ${e.status}... placing quartz into standby");
      try {
        scheduler.standby();
      } catch (SchedulerException e) {
        log.warn("Failed to place quartz scheduler into standby", e);
      }
    }
  }
}

@@ -653,16 +653,88 @@
 eline;%0A%0A
+import com.netflix.spinnaker.kork.discovery.DiscoveryStatusChangeEvent;%0A
 import c
@@ -1332,20 +1332,47 @@
 ) %7B%0A    
-if (
+DiscoveryStatusChangeEvent e = 
 event.ge
@@ -1376,24 +1376,36 @@
 .getSource()
+;%0A%0A    if (e
 .getStatus()
@@ -1453,34 +1453,25 @@
 Instance is 
-$%7Be.status
+%7B
 %7D... resumin
@@ -1489,16 +1489,31 @@
 heduler%22
+, e.getStatus()
 );%0A     
@@ -1573,32 +1573,33 @@
 dulerException e
+x
 ) %7B%0A        log.
@@ -1637,24 +1637,25 @@
 cheduler%22, e
+x
 );%0A      %7D%0A 
@@ -1762,18 +1762,9 @@
  is 
-$%7Be.status
+%7B
 %7D...
@@ -1792,16 +1792,31 @@
 standby%22
+, e.getStatus()
 );%0A     
@@ -1886,16 +1886,17 @@
 eption e
+x
 ) %7B%0A    
@@ -1958,16 +1958,17 @@
 ndby%22, e
+x
 );%0A     

Fix log lines in quartzdiscoveryactivator (#1052)