// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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 org.apache.cloudstack.outofbandmanagement;

import com.cloud.host.Host;
import org.apache.log4j.Logger;

public class PowerOperationTask implements Runnable {
    public static final Logger LOG = Logger.getLogger(PowerOperationTask.class);

    final private OutOfBandManagementService service;
    final private Host host;
    final private OutOfBandManagement.PowerOperation powerOperation;

    public PowerOperationTask(OutOfBandManagementService service, Host host, OutOfBandManagement.PowerOperation powerOperation) {
        this.service = service;
        this.host = host;
        this.powerOperation = powerOperation;
    }

    @Override
    public String toString() {
        return String.format("[OOBM Task] Power operation:%s on Host:%d(%s)", powerOperation, host.getId(), host.getName());
    }

    @Override
    public void run() {
        try {
            service.executePowerOperation(host, powerOperation, null);
        } catch (Exception e) {
            LOG.warn(String.format("Out-of-band management background task operation=%s for host id=%d failed with: %s",
                    powerOperation.name(), host.getId(), e.getMessage()));
        }
    }
}

@@ -868,16 +868,174 @@
 oud.
-host.Hos
+event.ActionEventUtils;%0Aimport com.cloud.event.EventTypes;%0Aimport com.cloud.event.EventVO;%0Aimport com.cloud.host.Host;%0Aimport org.apache.cloudstack.context.CallContex
 t;%0Ai
@@ -2029,13 +2029,10 @@
 ost 
-id=%25d
+%25s
  fai
@@ -2093,26 +2093,28 @@
 (), host.get
-Id
+Name
 (), e.getMes
@@ -2122,16 +2122,445 @@
 age()));
+%0A%0A            String eventMessage = String%0A                    .format(%22Error while issuing out-of-band management action %25s for host: %25s%22, powerOperation.name(), host.getName());%0A%0A            ActionEventUtils.onCreatedActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(), EventVO.LEVEL_WARN,%0A                    EventTypes.EVENT_HOST_OUTOFBAND_MANAGEMENT_ACTION, true, eventMessage);
 %0A       

Create Event in case of OOBM failure (#4418)