use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class SyncManager method refresh.
public void refresh() {
logger.debug("Refreshing state...");
try {
// Extract all registered APIs
Map<String, io.gravitee.repository.management.model.Api> apis = apiRepository.findAll().stream().collect(Collectors.toMap(io.gravitee.repository.management.model.Api::getId, api -> api));
// Get last event for each API
Map<String, Event> events = new HashMap<>();
apis.keySet().forEach(api -> {
Event event = getLastEvent(api);
events.put(api, event);
});
// Determine API which must be stopped and stop them
events.entrySet().stream().filter(apiEvent -> {
Event event = apiEvent.getValue();
return event != null && (event.getType() == EventType.STOP_API || event.getType() == EventType.UNPUBLISH_API);
}).forEach(apiEvent -> apiManager.undeploy(apiEvent.getKey()));
// Determine API which must be deployed
events.entrySet().stream().filter(apiEvent -> {
Event event = apiEvent.getValue();
return event != null && (event.getType() == EventType.START_API || event.getType() == EventType.PUBLISH_API);
}).forEach(apiEvent -> {
try {
// Read API definition from event
io.gravitee.repository.management.model.Api payloadApi = objectMapper.readValue(apiEvent.getValue().getPayload(), io.gravitee.repository.management.model.Api.class);
// API to deploy
ApiEntity apiToDeploy = convert(payloadApi);
if (apiToDeploy != null) {
// Get deployed API
ApiEntity deployedApi = apiManager.get(apiToDeploy.getId());
// API is not yet deployed, so let's do it !
if (deployedApi == null) {
apiManager.deploy(apiToDeploy);
} else {
if (deployedApi.getDeployedAt().before(apiToDeploy.getDeployedAt())) {
apiManager.update(apiToDeploy);
}
}
}
} catch (IOException ioe) {
logger.error("Error while determining deployed APIs store into events payload", ioe);
}
});
lastRefreshAt = System.currentTimeMillis();
} catch (TechnicalException te) {
logger.error("Unable to sync instance", te);
}
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class DynamicPropertiesService method onEvent.
@Override
public void onEvent(Event<ApiEvent, ApiEntity> event) {
final ApiEntity api = event.content();
switch(event.type()) {
case DEPLOY:
startDynamicProperties(api);
break;
case UNDEPLOY:
stopDynamicProperties(api);
break;
case UPDATE:
stopDynamicProperties(api);
startDynamicProperties(api);
break;
}
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiMembersResource method getPermissions.
@GET
@Path("/permissions")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get API members", notes = "User must have the MANAGE_MEMBERS permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "API member's permissions", response = MemberEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
public Response getPermissions(@PathParam("api") String api) {
final ApiEntity apiEntity = apiService.findById(api);
Map<String, char[]> permissions = new HashMap<>();
if (isAuthenticated()) {
final String userId = getAuthenticatedUser();
if (isAdmin()) {
final char[] rights = new char[] { CREATE.getId(), READ.getId(), UPDATE.getId(), DELETE.getId() };
for (ApiPermission perm : ApiPermission.values()) {
permissions.put(perm.getName(), rights);
}
} else {
permissions = membershipService.getMemberPermissions(apiEntity, userId);
}
}
return Response.ok(permissions).build();
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class HealthCheckServiceImpl method getAvailability.
@Override
public ApiMetrics getAvailability(String api, String field) {
logger.debug("Run health availability query for API '{}'", api);
try {
ApiEntity apiEntity = apiService.findById(api);
AvailabilityResponse response = healthCheckRepository.query(QueryBuilders.availability().api(api).field(AvailabilityQuery.Field.valueOf(field)).build());
return convert(apiEntity, response.getEndpointAvailabilities(), field);
} catch (Exception ex) {
logger.error("An unexpected error occurs while searching for health data.", ex);
return null;
}
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class TopApiServiceImpl method findAll.
@Override
public List<TopApiEntity> findAll() {
LOGGER.debug("Find all top APIs");
final List<ApiEntity> apis = parameterService.findAll(PORTAL_TOP_APIS.getKey(), apiId -> apiService.findById(apiId), apiService::exists);
if (!apis.isEmpty()) {
final List<TopApiEntity> topApis = new ArrayList<>(apis.size());
for (int i = 0; i < apis.size(); i++) {
final ApiEntity api = apis.get(i);
final TopApiEntity topApiEntity = new TopApiEntity();
topApiEntity.setApi(api.getId());
topApiEntity.setName(api.getName());
topApiEntity.setVersion(api.getVersion());
topApiEntity.setDescription(api.getDescription());
topApiEntity.setOrder(i);
topApis.add(topApiEntity);
}
return topApis;
}
return emptyList();
}
Aggregations