Search in sources :

Example 1 with SensorSetting

use of com.vmware.flowgate.common.model.SensorSetting in project flowgate by vmware.

the class SensorSettingControllerTest method udapteAnSensorSetting.

@Test
public void udapteAnSensorSetting() throws JsonProcessingException, Exception {
    SensorSetting sensorsetting = createSensorSetting();
    sensorSettingRepository.save(sensorsetting);
    sensorsetting.setMaxNum(25);
    this.mockMvc.perform(put("/v1/sensors/setting").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(sensorsetting))).andExpect(status().isOk()).andDo(document("sensorSetting-update-example", requestFields(fieldWithPath("id").description("ID of the sensorSetting, created by flowgate"), fieldWithPath("type").description("The sensor type."), fieldWithPath("minNum").description("Value type is double"), fieldWithPath("maxNum").description("Value type is double"), fieldWithPath("minValue").description("Value type is string"), fieldWithPath("maxValue").description("Value type is string"))));
    sensorSettingRepository.deleteById(sensorsetting.getId());
}
Also used : SensorSetting(com.vmware.flowgate.common.model.SensorSetting) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SensorSetting

use of com.vmware.flowgate.common.model.SensorSetting in project flowgate by vmware.

the class SensorSettingControllerTest method sensorQuerySettingByIDExample.

@Test
public void sensorQuerySettingByIDExample() throws Exception {
    SensorSetting sensorsetting = createSensorSetting();
    sensorSettingRepository.save(sensorsetting);
    this.mockMvc.perform(get("/v1/sensors/setting/" + sensorsetting.getId()).content("{\"id\":\"" + sensorsetting.getId() + "\"}")).andExpect(status().isOk()).andDo(document("sensorSetting-querySetting-example", responseFields(fieldWithPath("id").description("ID of the sensorSetting, created by flowgate"), fieldWithPath("type").description("The sensor type."), fieldWithPath("minNum").description("Value type is double"), fieldWithPath("maxNum").description("Value type is double"), fieldWithPath("minValue").description("Value type is string"), fieldWithPath("maxValue").description("Value type is string"))));
    sensorSettingRepository.deleteById(sensorsetting.getId());
}
Also used : SensorSetting(com.vmware.flowgate.common.model.SensorSetting) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with SensorSetting

use of com.vmware.flowgate.common.model.SensorSetting in project flowgate by vmware.

the class SensorSettingControllerTest method createAnSensorSetting.

@Test
public void createAnSensorSetting() throws JsonProcessingException, Exception {
    SensorSetting sensorsetting = createSensorSetting();
    this.mockMvc.perform(post("/v1/sensors/setting").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(sensorsetting))).andExpect(status().isCreated()).andDo(document("sensorSetting-create-example", requestFields(fieldWithPath("id").description("ID of the sensorSetting, created by flowgate"), fieldWithPath("type").description("The sensor type."), fieldWithPath("minNum").description("Value type is double"), fieldWithPath("maxNum").description("Value type is double"), fieldWithPath("minValue").description("Value type is string"), fieldWithPath("maxValue").description("Value type is string"))));
    sensorSettingRepository.deleteById(sensorsetting.getId());
}
Also used : SensorSetting(com.vmware.flowgate.common.model.SensorSetting) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with SensorSetting

use of com.vmware.flowgate.common.model.SensorSetting in project flowgate by vmware.

the class SensorSettingControllerTest method sensorSettingQueryByPageExample.

@Test
public void sensorSettingQueryByPageExample() throws Exception {
    SensorSetting sensorsetting = createSensorSetting();
    sensorSettingRepository.save(sensorsetting);
    int pageNumber = 1;
    int pageSize = 5;
    this.mockMvc.perform(get("/v1/sensors/setting/page/" + pageNumber + "/pagesize/" + pageSize + "").content("{\"pageNumber\":1,\"pageSize\":5}")).andExpect(status().isOk()).andExpect(jsonPath("$.content[0].maxNum").value(sensorsetting.getMaxNum())).andExpect(jsonPath("$..content.length()").value(1)).andExpect(jsonPath("last", is(true))).andExpect(jsonPath("number", is(0))).andExpect(jsonPath("size", is(5))).andExpect(jsonPath("first", is(true))).andDo(document("sensorSetting-queryByPage-example", requestFields(fieldWithPath("pageNumber").description("get datas for this page number."), fieldWithPath("pageSize").description("The number of data displayed per page."))));
    sensorSettingRepository.deleteById(sensorsetting.getId());
}
Also used : SensorSetting(com.vmware.flowgate.common.model.SensorSetting) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with SensorSetting

use of com.vmware.flowgate.common.model.SensorSetting in project flowgate by vmware.

the class AlertClient method checkPredefinedSymptoms.

private Map<String, SymptomDefinition> checkPredefinedSymptoms() {
    Map<String, SymptomDefinition> existSymptoms = getPredefinedSymptoms();
    if (existSymptoms.size() < predefinedSymptomNames.size()) {
        Set<String> missingSymptoms = new HashSet<String>(predefinedSymptomNames);
        missingSymptoms.removeAll(existSymptoms.keySet());
        createPredefinedSymptoms(missingSymptoms, existSymptoms);
    } else {
        // check whether we need to update the threshold of the symptoms
        List<SensorSetting> sensorSettings = new ArrayList<SensorSetting>();
        SensorSetting backTempSetting = new SensorSetting();
        backTempSetting.setMaxNum(35);
        backTempSetting.setType(MetricName.SERVER_BACK_TEMPREATURE);
        sensorSettings.add(backTempSetting);
        SensorSetting frontTempSetting = new SensorSetting();
        frontTempSetting.setMaxNum(35);
        frontTempSetting.setType(MetricName.SERVER_FRONT_TEMPERATURE);
        sensorSettings.add(frontTempSetting);
        SensorSetting backHumiditySetting = new SensorSetting();
        backHumiditySetting.setMaxNum(75);
        backHumiditySetting.setType(MetricName.SERVER_BACK_HUMIDITY);
        sensorSettings.add(backHumiditySetting);
        SensorSetting frontHumiditySetting = new SensorSetting();
        frontHumiditySetting.setMaxNum(75);
        frontHumiditySetting.setType(MetricName.SERVER_FRONT_HUMIDITY);
        sensorSettings.add(frontHumiditySetting);
        SensorSetting currentLoadSetting = new SensorSetting();
        currentLoadSetting.setMaxNum(67);
        currentLoadSetting.setType(MetricName.PDU_CURRENT_LOAD);
        sensorSettings.add(currentLoadSetting);
        Map<String, SensorSetting> symptomCondtionValues = getSymptomCondtionValues(sensorSettings);
        SymptomDefinitionsClient sd = getClient().symptomDefinitionsClient();
        for (SymptomDefinition symptom : existSymptoms.values()) {
            HTCondition condition = (HTCondition) symptom.getState().getCondition();
            SensorSetting sensorSetting = symptomCondtionValues.get(symptom.getName());
            if (sensorSetting != null) {
                if (!condition.getValue().equals((String.valueOf(sensorSetting.getMaxNum())))) {
                    condition.setValue(String.valueOf(sensorSetting.getMaxNum()));
                    sd.updateSymptomDefinition(symptom);
                }
            }
        }
    }
    return existSymptoms;
}
Also used : SymptomDefinition(com.vmware.ops.api.model.symptomdefinition.SymptomDefinition) ArrayList(java.util.ArrayList) HTCondition(com.vmware.ops.api.model.symptomdefinition.HTCondition) SensorSetting(com.vmware.flowgate.common.model.SensorSetting) SymptomDefinitionsClient(com.vmware.ops.api.client.controllers.SymptomDefinitionsClient) HashSet(java.util.HashSet)

Aggregations

SensorSetting (com.vmware.flowgate.common.model.SensorSetting)8 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)1 SymptomDefinitionsClient (com.vmware.ops.api.client.controllers.SymptomDefinitionsClient)1 HTCondition (com.vmware.ops.api.model.symptomdefinition.HTCondition)1 SymptomDefinition (com.vmware.ops.api.model.symptomdefinition.SymptomDefinition)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1