Commit c0f77bfa authored by Spiros Koulouzis's avatar Spiros Koulouzis

implemented monitoring message API

parent a2209702
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package nl.uva.sne.drip.api.dao; package nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse; import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult; import nl.uva.sne.drip.drip.commons.data.v1.external.ansible.AnsibleResult;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query; import org.springframework.data.mongodb.repository.Query;
......
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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 nl.uva.sne.drip.api.dao;
import nl.uva.sne.drip.drip.commons.data.v1.external.MonitorringMessage;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
*
* @author S. Koulouzis
*/
public interface MonitorringMessageDao extends MongoRepository<MonitorringMessage, String> {
}
...@@ -19,7 +19,6 @@ import java.io.IOException; ...@@ -19,7 +19,6 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import nl.uva.sne.drip.api.exception.NotFoundException; import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.commons.utils.Constants;
import nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation; import nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation;
import nl.uva.sne.drip.commons.utils.Converter; import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.drip.commons.data.v1.external.User; import nl.uva.sne.drip.drip.commons.data.v1.external.User;
......
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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 nl.uva.sne.drip.api.service;
import java.util.List;
import nl.uva.sne.drip.api.dao.MonitorringMessageDao;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.drip.commons.data.v1.external.DeployResponse;
import nl.uva.sne.drip.drip.commons.data.v1.external.MonitorringMessage;
import nl.uva.sne.drip.drip.commons.data.v1.external.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
@PreAuthorize("isAuthenticated()")
public class MonitorringMessageService {
@Autowired
private MonitorringMessageDao dao;
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public MonitorringMessage delete(String id) {
MonitorringMessage tr = dao.findOne(id);
if (tr == null) {
throw new NotFoundException();
}
dao.delete(tr);
return tr;
}
@PostFilter("(filterObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public List<MonitorringMessage> findAll() {
return dao.findAll();
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public MonitorringMessage findOne(String id) {
return dao.findOne(id);
}
@PostAuthorize("(hasRole('ROLE_ADMIN'))")
public void deleteAll() {
dao.deleteAll();
}
public MonitorringMessage save(MonitorringMessage message) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String owner = user.getUsername();
message.setOwner(owner);
return dao.save(message);
}
}
...@@ -23,9 +23,7 @@ import java.util.concurrent.TimeoutException; ...@@ -23,9 +23,7 @@ import java.util.concurrent.TimeoutException;
import nl.uva.sne.drip.api.dao.ToscaDao; import nl.uva.sne.drip.api.dao.ToscaDao;
import nl.uva.sne.drip.api.exception.NotFoundException; import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.rpc.DRIPCaller; import nl.uva.sne.drip.api.rpc.DRIPCaller;
import nl.uva.sne.drip.api.rpc.DeployerCaller;
import nl.uva.sne.drip.api.rpc.TransformerCaller; import nl.uva.sne.drip.api.rpc.TransformerCaller;
import nl.uva.sne.drip.commons.utils.Constants;
import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation; import nl.uva.sne.drip.drip.commons.data.v1.external.ToscaRepresentation;
import nl.uva.sne.drip.commons.utils.Converter; import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.drip.commons.data.internal.Message; import nl.uva.sne.drip.drip.commons.data.internal.Message;
......
/*
* Copyright 2017 S. Koulouzis.
*
* 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 nl.uva.sne.drip.api.v1.rest;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.security.RolesAllowed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import nl.uva.sne.drip.api.service.MonitorringMessageService;
import nl.uva.sne.drip.api.service.UserService;
import nl.uva.sne.drip.drip.commons.data.v1.external.MonitorringMessage;
import org.springframework.web.bind.annotation.RequestBody;
/**
* This controller is responsible for storing TOSCA descriptions that can be
* used by the planner.
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/user/v1.0/monitorring_message")
@Component
@StatusCodes({
@ResponseCode(code = 401, condition = "Bad credentials")
})
public class MonitorringMessageController {
@Autowired
private MonitorringMessageService monitorringMessageService;
@RequestMapping(value = "/", method = RequestMethod.POST)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
String post(@RequestBody MonitorringMessage message) {
return monitorringMessageService.save(message).getId();
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET, params = {"format"})
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
MonitorringMessage get(@PathVariable("id") String id, @RequestParam(value = "format") String format) {
return monitorringMessageService.findOne(id);
}
/**
* Gets the IDs of all the stored TOSCA descriptions.
*
* @return a list of all the IDs
*/
@RequestMapping(value = "/ids", method = RequestMethod.GET)
@RolesAllowed({UserService.USER, UserService.ADMIN})
public @ResponseBody
List<String> getIds() {
List<MonitorringMessage> all = monitorringMessageService.findAll();
List<String> ids = new ArrayList<>();
for (MonitorringMessage tr : all) {
ids.add(tr.getId());
}
return ids;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* 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 nl.uva.sne.drip.drip.commons.data.v1.external;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.webcohesion.enunciate.metadata.DocumentationExample;
import org.springframework.data.mongodb.core.mapping.Document;
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MonitorringMessage extends OwnedObject {
private String metricMame;
private String subid;
private double value;
private String messageType;
/**
* @return the metricMame
*/
@DocumentationExample("cpuTotal")
public String getMetricMame() {
return metricMame;
}
/**
* @param metricMame the metricMame to set
*/
public void setMetricMame(String metricMame) {
this.metricMame = metricMame;
}
/**
* @return the subid
*/
@DocumentationExample("1ccba0cc92174ce788695cfc0a027b57")
public String getSubid() {
return subid;
}
/**
* @param subid the subid to set
*/
public void setSubid(String subid) {
this.subid = subid;
}
/**
* @return the value
*/
@DocumentationExample("91.0500021021063106")
public double getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(double value) {
this.value = value;
}
/**
* @return the messageType
*/
@DocumentationExample("critical")
public String getMessageType() {
return messageType;
}
/**
* @param messageType the messageType to set
*/
public void setMessageType(String messageType) {
this.messageType = messageType;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment