org.rapidoid.annotation.GET Java Examples

The following examples show how to use org.rapidoid.annotation.GET. 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 File: DeployableVersionController.java    From apollo with 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 #2
Source File: StatusController.java    From apollo with 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 #3
Source File: StatusController.java    From apollo with 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 #4
Source File: StatusController.java    From apollo with 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 #5
Source File: StatusController.java    From apollo with 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 #6
Source File: StatusController.java    From apollo with 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 #7
Source File: DatatablesController.java    From apollo with 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 #8
Source File: ScalingController.java    From apollo with 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 #9
Source File: HealthController.java    From apollo with 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 #10
Source File: HttpBeanParamsTest.java    From rapidoid with 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 #11
Source File: BlockerDefinitionController.java    From apollo with 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 #12
Source File: HttpReregistrationTest.java    From rapidoid with 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 #13
Source File: HttpBeanParamsTest.java    From rapidoid with 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 #14
Source File: AuthController.java    From apollo with 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 File: GenericStackController.java    From apollo with 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 #16
Source File: EnvironmentController.java    From apollo with 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 #17
Source File: HttpPojoControllerTest.java    From rapidoid with 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 #18
Source File: EnvironmentsStackController.java    From apollo with 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 #19
Source File: ServicesStackController.java    From apollo with 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 #20
Source File: StatusController.java    From apollo with 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 #21
Source File: StatusController.java    From apollo with 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 #22
Source File: ServicesStackController.java    From apollo with 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 #23
Source File: ServiceController.java    From apollo with Apache License 2.0 4 votes vote down vote up
@LoggedIn
@GET("/service/{id}")
public Service getService(int id) {
    return serviceDao.getService(id);
}
 
Example #24
Source File: NotificationController.java    From apollo with Apache License 2.0 4 votes vote down vote up
@LoggedIn
@GET("/notification")
public List<Notification> getAllNotifications() {
    return notificationDao.getAllNotifications();
}
 
Example #25
Source File: NotificationController.java    From apollo with Apache License 2.0 4 votes vote down vote up
@LoggedIn
@GET("/notification/{id}")
public Notification getNotification(int id) {
    return notificationDao.getNotification(id);
}
 
Example #26
Source File: MyCtrl.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
@GET
@Roles("manager")
public Object manage() {
	return "Welcome, Mr. Manager!";
}
 
Example #27
Source File: ScalingController.java    From apollo with Apache License 2.0 4 votes vote down vote up
@LoggedIn
@GET("/scaling/apollo-factor/{groupId}")
public int getScalingFactor(int groupId) {
    return groupDao.getScalingFactor(groupId);
}
 
Example #28
Source File: MyCtrl.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
@GET("/add")
public Object add(int x, int y) {
	return U.map("sum", math.add(x, y));
}
 
Example #29
Source File: MyCtrl.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
@GET("/")
public Object home() {
	return "This is public!";
}
 
Example #30
Source File: Bar.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
@GET("/hi")
public String hello() {
	return foo.msg();
}