Add alarm message persistent method. (#1738)
This commit is contained in:
parent
1a49f7053c
commit
1955e9d3cf
|
|
@ -18,19 +18,18 @@
|
|||
|
||||
package org.apache.skywalking.oap.server.core.alarm;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.*;
|
||||
import org.apache.skywalking.oap.server.core.source.Scope;
|
||||
|
||||
/**
|
||||
* Alarm message represents the details of each alarm.
|
||||
*
|
||||
* @author wusheng
|
||||
* @author wusheng, peng-yongsheng
|
||||
*/
|
||||
@Setter(AccessLevel.PUBLIC)
|
||||
@Getter(AccessLevel.PUBLIC)
|
||||
public class AlarmMessage {
|
||||
|
||||
public static AlarmMessage NONE = new NoAlarm();
|
||||
|
||||
private Scope scope;
|
||||
|
|
@ -38,6 +37,7 @@ public class AlarmMessage {
|
|||
private int id0;
|
||||
private int id1;
|
||||
private String alarmMessage;
|
||||
private long timeBucket;
|
||||
|
||||
private static class NoAlarm extends AlarmMessage {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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.skywalking.oap.server.core.alarm;
|
||||
|
||||
import java.util.*;
|
||||
import lombok.*;
|
||||
import org.apache.skywalking.oap.server.core.Const;
|
||||
import org.apache.skywalking.oap.server.core.analysis.record.Record;
|
||||
import org.apache.skywalking.oap.server.core.analysis.record.annotation.RecordType;
|
||||
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
|
||||
import org.apache.skywalking.oap.server.core.storage.annotation.*;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@RecordType
|
||||
@StorageEntity(name = AlarmRecord.INDEX_NAME, builder = AlarmRecord.Builder.class)
|
||||
public class AlarmRecord extends Record {
|
||||
|
||||
public static final String INDEX_NAME = "alarm_record";
|
||||
private static final String SCOPE = "scope";
|
||||
private static final String NAME = "name";
|
||||
private static final String ID0 = "id0";
|
||||
private static final String ID1 = "id1";
|
||||
private static final String ALARM_MESSAGE = "alarm_message";
|
||||
|
||||
@Override public String id() {
|
||||
return getTimeBucket() + Const.ID_SPLIT + scope + Const.ID_SPLIT + id0 + Const.ID_SPLIT + id1;
|
||||
}
|
||||
|
||||
@Column(columnName = SCOPE) private int scope;
|
||||
@Column(columnName = NAME) private String name;
|
||||
@Column(columnName = ID0) private int id0;
|
||||
@Column(columnName = ID1) private int id1;
|
||||
@Column(columnName = ALARM_MESSAGE, matchQuery = true) private String alarmMessage;
|
||||
|
||||
public static class Builder implements StorageBuilder<AlarmRecord> {
|
||||
|
||||
@Override public Map<String, Object> data2Map(AlarmRecord storageData) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put(SCOPE, storageData.getScope());
|
||||
map.put(NAME, storageData.getName());
|
||||
map.put(ID0, storageData.getId0());
|
||||
map.put(ID1, storageData.getId1());
|
||||
map.put(ALARM_MESSAGE, storageData.getAlarmMessage());
|
||||
map.put(TIME_BUCKET, storageData.getTimeBucket());
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override public AlarmRecord map2Data(Map<String, Object> dbMap) {
|
||||
AlarmRecord record = new AlarmRecord();
|
||||
record.setScope(((Number)dbMap.get(SCOPE)).intValue());
|
||||
record.setName((String)dbMap.get(NAME));
|
||||
record.setId0(((Number)dbMap.get(ID0)).intValue());
|
||||
record.setId1(((Number)dbMap.get(ID1)).intValue());
|
||||
record.setAlarmMessage((String)dbMap.get(ALARM_MESSAGE));
|
||||
record.setTimeBucket(((Number)dbMap.get(TIME_BUCKET)).longValue());
|
||||
return record;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,15 +19,26 @@
|
|||
package org.apache.skywalking.oap.server.core.alarm;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.oap.server.core.analysis.worker.RecordProcess;
|
||||
|
||||
/**
|
||||
* Save the alarm info into storage for UI query.
|
||||
*
|
||||
* @author wusheng, peng-yongsheng
|
||||
*/
|
||||
public class AlarmStandardPersistence implements AlarmCallback {
|
||||
|
||||
@Override public void doAlarm(List<AlarmMessage> alarmMessage) {
|
||||
//TODO Peng-yongsheng
|
||||
/**
|
||||
* This is just a callback entrance.
|
||||
*/
|
||||
alarmMessage.forEach(message -> {
|
||||
AlarmRecord record = new AlarmRecord();
|
||||
record.setScope(message.getScope().ordinal());
|
||||
record.setId0(message.getId0());
|
||||
record.setId1(message.getId1());
|
||||
record.setName(message.getName());
|
||||
record.setAlarmMessage(message.getAlarmMessage());
|
||||
record.setTimeBucket(message.getTimeBucket());
|
||||
|
||||
RecordProcess.INSTANCE.in(record);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue