Java Code Examples for org.rapidoid.annotation.GET

The following examples show how to use org.rapidoid.annotation.GET. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: apollo   Source File: StatusController.java    License: Apache License 2.0 6 votes vote down vote up
@GET("/status/environment/{envId}/service/{serviceId}/group/{groupName}")
public KubernetesDeploymentStatus getOneSpecificStatusWithGroup(int envId, int serviceId, String groupName) {

    Environment environment = environmentDao.getEnvironment(envId);
    KubernetesHandler kubernetesHandler = kubernetesHandlerStore.getOrCreateKubernetesHandler(environment);
    Service service = serviceDao.getService(serviceId);
    KubernetesDeploymentStatus kubernetesDeploymentStatus = null;

    if (service != null) {
        try {
            kubernetesDeploymentStatus = kubernetesHandler.getCurrentStatus(service, Optional.of(groupName));
            kubernetesDeploymentStatus.setGitCommitUrl(getCommitUrl(kubernetesDeploymentStatus, serviceId));
        } catch (Exception e) {
            logger.warn("Could not get status of service {}, on environment {}, group {}!", service.getId(), envId, groupName, e);
        }
    }

    return kubernetesDeploymentStatus;
}
 
Example 2
Source Project: apollo   Source File: StatusController.java    License: Apache License 2.0 6 votes vote down vote up
@GET("/status/environment/{envId}/service/{serviceId}/all-groups")
public List<KubernetesDeploymentStatus> getStatusesWithGroups(int envId, int serviceId) {

    Environment environment = environmentDao.getEnvironment(envId);
    KubernetesHandler kubernetesHandler = kubernetesHandlerStore.getOrCreateKubernetesHandler(environment);
    Service service = serviceDao.getService(serviceId);
    List<KubernetesDeploymentStatus> kubernetesDeploymentStatuses = new ArrayList<>();

    if (service != null) {
        List<Group> groups = groupDao.getGroupsPerServiceAndEnvironment(serviceId,envId);
        try {
            groups.forEach(group -> {
                KubernetesDeploymentStatus kubernetesDeploymentStatus = kubernetesHandler.getCurrentStatus(service, Optional.of(group.getName()));
                kubernetesDeploymentStatus.setGitCommitUrl(getCommitUrl(kubernetesDeploymentStatus, serviceId));
                kubernetesDeploymentStatuses.add(kubernetesDeploymentStatus);
            });
        } catch (Exception e) {
            logger.warn("Could not get status of service {}, on environment {}!", service.getId(), envId, e);
        }
    }

    return kubernetesDeploymentStatuses;
}
 
Example 3
Source Project: apollo   Source File: StatusController.java    License: Apache License 2.0 6 votes vote down vote up
@GET("/status/environment/{envId}/service/{serviceId}")
public KubernetesDeploymentStatus getOneSpecificStatus(int envId, int serviceId) {

    Environment environment = environmentDao.getEnvironment(envId);
    KubernetesHandler kubernetesHandler = kubernetesHandlerStore.getOrCreateKubernetesHandler(environment);
    Service service = serviceDao.getService(serviceId);
    KubernetesDeploymentStatus kubernetesDeploymentStatus = null;

    if (service != null) {
        try {
            kubernetesDeploymentStatus = kubernetesHandler.getCurrentStatus(service);
            kubernetesDeploymentStatus.setGitCommitUrl(getCommitUrl(kubernetesDeploymentStatus, serviceId));
        } catch (Exception e) {
            logger.warn("Could not get status of service {}, on environment {}!", service.getId(), envId, e);
        }
    }

    return  kubernetesDeploymentStatus;
}
 
Example 4
Source Project: apollo   Source File: StatusController.java    License: Apache License 2.0 6 votes vote down vote up
@LoggedIn
@GET("/status/environment/{environmentId}/service/{serviceId}/latestpod")
public String getLatestPodName(int environmentId, int serviceId, Req req) {
    Environment environment = environmentDao.getEnvironment(environmentId);
    Service service = serviceDao.getService(serviceId);

    if (service.getIsPartOfGroup()) {
        ControllerCommon.assignJsonResponseToReq(req, HttpStatus.NOT_ACCEPTABLE, "Missing group ID for service " + service.getId());
        return "";
    }

    KubernetesHandler kubernetesHandler = kubernetesHandlerStore.getOrCreateKubernetesHandler(environment);

    Optional<String> serviceLatestCreatedPodName = kubernetesHandler.getServiceLatestCreatedPodName(service);
    if (serviceLatestCreatedPodName.isPresent()) {
        return serviceLatestCreatedPodName.get();
    } else {
        ControllerCommon.assignJsonResponseToReq(req, HttpStatus.NOT_FOUND, "Can't find pod");
        return "";
    }
}
 
Example 5
Source Project: apollo   Source File: StatusController.java    License: Apache License 2.0 6 votes vote down vote up
@LoggedIn
@GET("/status/environment/{environmentId}/service/{serviceId}/group/{groupName}/latestpod")
public String getLatestPodName(int environmentId, int serviceId, String groupName, Req req) {
    Environment environment = environmentDao.getEnvironment(environmentId);
    Service service = serviceDao.getService(serviceId);

    if (!service.getIsPartOfGroup()) {
        ControllerCommon.assignJsonResponseToReq(req, HttpStatus.NOT_ACCEPTABLE, "Service " + service.getId() + " can't have group ID");
        return "";
    }

    KubernetesHandler kubernetesHandler = kubernetesHandlerStore.getOrCreateKubernetesHandler(environment);

    Optional<String> serviceLatestCreatedPodName = kubernetesHandler.getServiceLatestCreatedPodName(service, Optional.of(groupName));
    if (serviceLatestCreatedPodName.isPresent()) {
        return serviceLatestCreatedPodName.get();
    } else {
        ControllerCommon.assignJsonResponseToReq(req, HttpStatus.NOT_FOUND, "Can't find pod");
        return "";
    }
}
 
Example 6
Source Project: rapidoid   Source File: HttpBeanParamsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@ExpectErrors
public void testBeanParams() {
	App.beans(new Object() {

		@GET
		@SuppressWarnings("unchecked")
		public List<Object> pers(String name, Person person, int id, Integer xx) {
			return U.list(id, name, person, xx);
		}

	});

	onlyGet("/pers?name=Einstein&id=1000");
	onlyGet("/pers?name=Mozart");
	onlyGet("/pers?id=200");
}
 
Example 7
Source Project: apollo   Source File: HealthController.java    License: Apache License 2.0 6 votes vote down vote up
@GET("/health")
public void getHealth(Req req) {
    Set<Integer> scopedEnvironments = slaveService.getScopedEnvironments();
    Map<Integer, Boolean> environmentsHealthMap = kubernetesHealth.getEnvironmentsHealthMap();

    Map<Integer, Boolean> scopedEnvironmentsHealthMap = new HashMap<>(environmentsHealthMap);

    environmentsHealthMap.keySet()
                         .stream()
                         .filter(envId -> !scopedEnvironments.contains(envId))
                         .forEach(scopedEnvironmentsHealthMap::remove);

    if (scopedEnvironmentsHealthMap.containsValue(false)) {
        scopedEnvironmentsHealthMap.entrySet()
                             .stream()
                             .filter(environment -> !environment.getValue())
                             .forEach(environment -> {
                                 MDC.put("environmentId", String.valueOf(environment.getKey()));
                                 MDC.put("environmentName", String.valueOf(environmentDao.getEnvironment(environment.getKey()).getName()));
                                 logger.error("Unhealthy environment, environmentId: {}, environmentName: {}.", environment.getKey(), environmentDao.getEnvironment(environment.getKey()).getName());
                             });
        assignJsonResponseToReq(req, HttpStatus.INTERNAL_SERVER_ERROR, scopedEnvironmentsHealthMap);
    } else {
        assignJsonResponseToReq(req, HttpStatus.OK, scopedEnvironmentsHealthMap);
    }
}
 
Example 8
Source Project: apollo   Source File: DatatablesController.java    License: Apache License 2.0 6 votes vote down vote up
@LoggedIn
@GET("/deployment/datatables")
public DataTablesResponseObject getDataTableDeploymentResponse(Req req) {

    Map<String, String> queryStringMap = StringParser.getQueryStringMap(req.query());

    int draw = Integer.parseInt(queryStringMap.get("draw"));
    int length = Integer.parseInt(queryStringMap.get("length"));
    int start = Integer.parseInt(queryStringMap.get("start"));
    String search = "%" + queryStringMap.get("search[value]") + "%";
    String orderDirectionString = queryStringMap.get("order[0][dir]");


    DataTablesResponseObject dataTablesResponseObject = new DataTablesResponseObject();
    dataTablesResponseObject.draw = draw;
    dataTablesResponseObject.recordsFiltered = deploymentDao.getFilteredDeploymentHistoryCount(search);
    dataTablesResponseObject.recordsTotal = deploymentDao.getTotalDeploymentsCount();

    dataTablesResponseObject.data = deploymentDao.filterDeploymentHistoryDetails(search, OrderDirection.valueOf(orderDirectionString.toUpperCase()), start, length);

    return dataTablesResponseObject;
}
 
Example 9
Source Project: apollo   Source File: DeployableVersionController.java    License: Apache License 2.0 6 votes vote down vote up
@LoggedIn
@GET("/deployable-version/latest/branch/{branchName}/repofrom/{deployableVersionId}")
public DeployableVersion getLatestDeployableVersionOnBranchBasedOnOtherDeployableVersion(String branchName, int deployableVersionId, Req req) {
    DeployableVersion referenceDeployableVersion = deployableVersionDao.getDeployableVersion(deployableVersionId);
    String actualRepo = getRepoNameFromRepositoryUrl(referenceDeployableVersion.getGithubRepositoryUrl());

    Optional<String> latestSha = githubConnector.getLatestCommitShaOnBranch(actualRepo, branchName);

    if (!latestSha.isPresent()) {
        assignJsonResponseToReq(req, HttpStatus.BAD_REQUEST, "Did not found latest commit on that branch");
        throw new RuntimeException();
    }

    DeployableVersion deployableVersionFromSha = deployableVersionDao.getDeployableVersionFromSha(latestSha.get(),
            referenceDeployableVersion.getServiceId());

    if (deployableVersionFromSha == null) {
        assignJsonResponseToReq(req, HttpStatus.BAD_REQUEST, "Did not found deployable version matching the sha " + latestSha);
        throw new RuntimeException();
    } else {
        return deployableVersionFromSha;
    }
}
 
Example 10
Source Project: apollo   Source File: ScalingController.java    License: Apache License 2.0 6 votes vote down vote up
@LoggedIn
@GET("/scaling/kubernetes-factor/{groupId}")
public void getKubeScalingFactor(int groupId, Req req) {
    Group group = groupDao.getGroup(groupId);

    if (group == null) {
        assignJsonResponseToReq(req, HttpStatus.NOT_FOUND, groupId);
        return;
    }

    Environment environment = environmentDao.getEnvironment(group.getEnvironmentId());
    KubernetesHandler kubernetesHandler = kubernetesHandlerStore.getOrCreateKubernetesHandler(environment);
    try {
        int scalingFactor = kubernetesHandler.getScalingFactor(serviceDao.getService(group.getServiceId()), group.getName());
        assignJsonResponseToReq(req, HttpStatus.OK, scalingFactor);
    } catch (ApolloNotFoundException e) {
        assignJsonResponseToReq(req, HttpStatus.NOT_FOUND, e.getMessage());
    }
}
 
Example 11
Source Project: apollo   Source File: StatusController.java    License: Apache License 2.0 5 votes vote down vote up
@LoggedIn
@GET("/status/environment/{environmentId}/pod/{podName}/containers")
public List<String> getPodContainers(int environmentId, String podName) {
    Environment environment = environmentDao.getEnvironment(environmentId);
    KubernetesHandler kubernetesHandler = kubernetesHandlerStore.getOrCreateKubernetesHandler(environment);

    return kubernetesHandler.getPodContainerNames(podName);
}
 
Example 12
Source Project: apollo   Source File: StatusController.java    License: Apache License 2.0 5 votes vote down vote up
@GET("/status/get-undeployed-services/avaiability/{availability}/time-unit/{timeUnit}/duration/{duration}")
public List<EnvironmentServiceGroupMap> getUndeployedServicesByAvailability(String availability, String timeUnit, int duration) {
    TimeUnit timeUnitEnum;
    try {
        timeUnitEnum = TimeUnit.valueOf(timeUnit);
    } catch (IllegalArgumentException | NullPointerException e) {
        throw new IllegalArgumentException("Please pass timeUnit parameter in TimeUnit type template", e.getCause());
    }
    return serviceStatusHandler.getUndeployedServicesByAvailability(availability, timeUnitEnum, duration);
}
 
Example 13
Source Project: apollo   Source File: BlockerDefinitionController.java    License: Apache License 2.0 5 votes vote down vote up
@LoggedIn
@GET("/blocker-definition/unconditional/regions/{regionsCsv}/environment-types/{environmentTypesCsv}")
public List<Integer> getUnconditionalBlockersByEnvironmentTypeAndRegion(String regionsCsv, String environmentTypesCsv) {
    Iterable<String> regions = Splitter.on(CSV_DELIMITER).omitEmptyStrings().trimResults().split(regionsCsv);
    Iterable<String> environmentTypes = Splitter.on(CSV_DELIMITER).omitEmptyStrings().trimResults().split(environmentTypesCsv);
    return blockerDefinitionDao.getUnconditionalBlockersByEnvironmentTypeAndRegion(Lists.newArrayList(regions), Lists.newArrayList(environmentTypes));
}
 
Example 14
Source Project: apollo   Source File: AuthController.java    License: Apache License 2.0 5 votes vote down vote up
@LoggedIn
@GET("/users")
public List<User> getAllUsers() {
    return userDao.getAllUsers().stream()
            .map(this::maskPassword)
            .collect(Collectors.toList());
}
 
Example 15
Source Project: rapidoid   Source File: HttpPojoControllerTest.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testPojoHandlers() {
	App.beans(new Object() {

		@GET(uri = "/a")
		public Object theFoo() {
			return "foo";
		}

		@POST(uri = "/x")
		public Object x(Req req, Resp resp) {
			return "x";
		}
	});

	onlyGet("/a");
	onlyPost("/x");
	notFound("/b");

	List<String> ctrls = Scan.annotated(MyTestController.class).in("pkg1", "pkg2").getAll();
	isTrue(ctrls.isEmpty());

	List<String> ctrls2 = Scan.annotated(MyTestController.class).in("non-existing-pkg", "").getAll();
	eq(ctrls2, U.list(Ff.class.getName()));

	Scan.annotated(MyTestController.class, MyTestController.class).in(App.path()).forEach(App::beans);

	onlyGet("/a");
	onlyGet("/b");
	onlyPost("/x");
}
 
Example 16
Source Project: apollo   Source File: EnvironmentsStackController.java    License: Apache License 2.0 5 votes vote down vote up
@LoggedIn
@Transactional
@GET("/environments-stack/{stackId}")
public EnvironmentsStack getEnvironmentsStack(int stackId) {
    EnvironmentsStack environmentsStack = stackDao.getEnvironmentsStack(stackId);
    environmentsStack.setEnvironments(environmentsStackDao.getEnvironments(stackId));
    return environmentsStack;
}
 
Example 17
Source Project: apollo   Source File: ServicesStackController.java    License: Apache License 2.0 5 votes vote down vote up
@LoggedIn
@Transactional
@GET("/services-stack/{stackId}")
public ServicesStack getServicesStack(int stackId) {
    ServicesStack servicesStack = stackDao.getServicesStack(stackId);
    servicesStack.setServices(servicesStackDao.getServices(stackId));
    return servicesStack;
}
 
Example 18
Source Project: apollo   Source File: ServicesStackController.java    License: Apache License 2.0 5 votes vote down vote up
@LoggedIn
@GET("/services-stack")
public List<ServicesStack> getAllServicesStacks() {
    List<ServicesStack> servicesStacks = stackDao.getAllServicesStacks();
    return servicesStacks.stream().map(stack -> {
        List<Integer> services = servicesStackDao.getServices(stack.getId());
        return new ServicesStack(stack.getId(), stack.getName(), stack.isEnabled(), services);
    }).collect(Collectors.toList());
}
 
Example 19
Source Project: apollo   Source File: GenericStackController.java    License: Apache License 2.0 5 votes vote down vote up
@LoggedIn
@Transactional
@GET("/stack")
public List<Stack> getAllStacks() {
    List<Stack> allStacks = new ArrayList<>();
    allStacks.addAll(stackDao.getAllServicesStacks());
    allStacks.addAll(stackDao.getAllEnvironmentsStacks());
    return allStacks;
}
 
Example 20
Source Project: rapidoid   Source File: HttpBeanParamsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPrimitiveLambdaParams() {
	App.beans(new Object() {
		@GET
		public Object foo(double a, double b, double c) {
			return U.join(":", a, b, c);
		}
	});

	onlyGet("/foo?a=10&b=20&c=30");
}
 
Example 21
Source Project: rapidoid   Source File: HttpReregistrationTest.java    License: Apache License 2.0 5 votes vote down vote up
private Object ctrl1(String prefix) {
	class AbcCtrl {
		@GET
		String inc(Integer x) {
			return prefix + (x + 1);
		}
	}

	return new AbcCtrl();
}
 
Example 22
Source Project: apollo   Source File: EnvironmentController.java    License: Apache License 2.0 5 votes vote down vote up
@LoggedIn
@GET("/environment/{id}")
public Environment getEnvironment(int id) {
    Environment gotEnvironment = environmentDao.getEnvironment(id);
    gotEnvironment = maskCredentials(gotEnvironment);
    return gotEnvironment;
}
 
Example 23
Source Project: rpc-benchmark   Source File: ListUserController.java    License: Apache License 2.0 4 votes vote down vote up
@GET("list-user")
public Page<User> getUser(int pageNo) {
	Page<User> userList = userService.listUser(pageNo);
	return userList;
}
 
Example 24
Source Project: rpc-benchmark   Source File: CreateUserController.java    License: Apache License 2.0 4 votes vote down vote up
@GET("create-user")
public boolean createUser(User user) {
	return userService.createUser(user);
}
 
Example 25
Source Project: rpc-benchmark   Source File: UserExistController.java    License: Apache License 2.0 4 votes vote down vote up
@GET("user-exist")
public boolean emailExist(String email) {
	return userService.existUser(email);
}
 
Example 26
Source Project: rpc-benchmark   Source File: GetUserController.java    License: Apache License 2.0 4 votes vote down vote up
@GET("get-user")
public User getUser(int id) {
	User user = userService.getUser(id);
	return user;
}
 
Example 27
Source Project: apollo   Source File: BlockerDefinitionController.java    License: Apache License 2.0 4 votes vote down vote up
@LoggedIn
@GET("/blocker-definition")
public List<BlockerDefinition> getAllBlockerDefinitions() {
    return blockerDefinitionDao.getAllBlockerDefinitions();
}
 
Example 28
Source Project: apollo   Source File: BlockerDefinitionController.java    License: Apache License 2.0 4 votes vote down vote up
@LoggedIn
@GET("/blocker-definition/unconditional")
public List<Integer> getUnconditionalBlockers() {
    return blockerDefinitionDao.getUnconditionalBlockers();
}
 
Example 29
Source Project: apollo   Source File: BlockerDefinitionController.java    License: Apache License 2.0 4 votes vote down vote up
@LoggedIn
@GET("/blocker-definition/unconditional/regions/{regionsCsv}")
public List<Integer> getUnconditionalBlockersByRegion(String regionsCsv) {
    Iterable<String> regions = Splitter.on(CSV_DELIMITER).omitEmptyStrings().trimResults().split(regionsCsv);
    return blockerDefinitionDao.getUnconditionalBlockersByRegion(Lists.newArrayList(regions));
}
 
Example 30
Source Project: apollo   Source File: BlockerDefinitionController.java    License: Apache License 2.0 4 votes vote down vote up
@LoggedIn
@GET("/blocker-definition/{id}")
public BlockerDefinition getBlockerDefinition(int id) {
    return blockerDefinitionDao.getBlockerDefinition(id);
}