Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/endpoint to sync #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test-output/
.classpath
.settings/
.metadata/
**TestingPivotalClient.java

.idea/
*.iml
Expand All @@ -30,3 +31,4 @@ brooklyn*.log.*
*brooklyn-persisted-state/

ignored
**pivotal.properties
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Integrate TOSCA-based object model.
- Integrate Lombok
- Dockerized testing

34 changes: 34 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,41 @@
<scope>test</scope>
</dependency>

<!--<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>-->

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6</version>
<scope>test</scope>
</dependency>


</dependencies>


<!--<build>-->
<!--<plugins>-->
<!--<plugin>-->
<!--<groupId>org.projectlombok</groupId>-->
<!--<artifactId>lombok-maven-plugin</artifactId>-->
<!--<version>1.18.10.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>generate-sources</phase>-->
<!--<goals>-->
<!--<goal>delombok</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<!--</plugins>-->
<!--</build>-->



</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.scenic.orchestrator.config;

import org.scenic.orchestrator.core.pivotal.PivotalClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
* Created by Jose on 10/12/19.
*/
@Configuration
@PropertySource("classpath:pivotal.properties")
public class PivotalClientConfiguration {

@Value("${pivotalUser}")
private String pivotalUser;

@Value("${pivotalPass}")
private String pivotalPass;

@Bean
public PivotalClient pivotalClient() {
return new PivotalClient(pivotalUser, pivotalPass);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.scenic.orchestrator.config;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.scenic.orchestrator.core.service.plan.PlanStepExecutor;
import org.scenic.orchestrator.core.service.plan.strategy.ParallelStepExecutorStrategy;
import org.scenic.orchestrator.core.service.plan.strategy.SingleStepExecutorStrategy;
import org.scenic.orchestrator.manager.ManagerAnalyzerClient;
import org.scenic.orchestrator.manager.SecuentialManagerAnalyzerClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.client.RestTemplate;

/**
* Created by Jose on 01/10/19.
*/
@Configuration
public class ThreadPoolExecutorConfig {

@Bean(destroyMethod = "shutdown")
public ExecutorService executorService() {
return Executors.newFixedThreadPool(10);
}

@Bean
@Profile("!secuential")
ParallelStepExecutorStrategy parallelStepExecutorStrategy(PlanStepExecutor planStepExecutor,
ExecutorService executorService) {
return new ParallelStepExecutorStrategy(planStepExecutor, executorService);
}

@Bean
@Profile("!secuential")
ManagerAnalyzerClient managerAnalyzerClient(RestTemplate restTemplate){
return new ManagerAnalyzerClient(restTemplate);
}

@Bean
@Profile("secuential")
SingleStepExecutorStrategy singleStepExecutorStrategy(PlanStepExecutor planStepExecutor) {
return new SingleStepExecutorStrategy(planStepExecutor);
}


@Bean
@Profile("secuential")
ManagerAnalyzerClient secuentialManagerAnalyzerClient(RestTemplate restTemplate){
return new SecuentialManagerAnalyzerClient(restTemplate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.scenic.orchestrator.core;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
* Created by Jose on 17/10/19.
*/
@ConditionalOnProperty(name="scheduleUpdating")
@Component
public class UpdateStatusScheduler {

private final UpdaterManagement updaterManagement;

public UpdateStatusScheduler(UpdaterManagement updaterManagement) {
this.updaterManagement = updaterManagement;
}

@Scheduled(fixedRateString = "${instructionSchedularTime}")
public void deployApp() throws InterruptedException {
updaterManagement.updateApplication();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
@Component
public class UpdaterManagement {


private final ManagementContext managementContext;
private PlanManager planManager;

Expand All @@ -24,8 +23,7 @@ public UpdaterManagement(ManagementContext managementContext, PlanManager planMa
this.planManager = planManager;
}


@Scheduled(fixedRateString = "${instructionSchedularTime}")
//@Scheduled(fixedRateString = "${instructionSchedularTime}")
public void updateApplication() {

List<RunningAppContext> applicationsToUpdate = MutableList.of();
Expand All @@ -41,6 +39,7 @@ public void updateApplication() {

@Async("threadPoolTaskExecutor")
public void manageApplication(RunningAppContext appContext){
System.out.println("Checking updating");
planManager.update(appContext);
managementContext.addRunningAppContext(appContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ public class DeployerProxy {

private static final String START_EFFECTOR_NAME = "start";
private static final String STOP_EFFECTOR_NAME = "stop";
private static final String RESTART_EFFECTOR_NAME = "restart";

private static final String STOP_MACHINE_MODE = "stopMachineMode";
private static final String STOP_MACHINE_IF_NOT_STOPPED = "IF_NOT_STOPPED";

private static final String STOP_PROCESS_MODE = "stopProcessMode";
private static final String STOP_PROCESS_MODE_NEVER = "NEVER";

private final BrooklynApi brooklynApi;
private final ApplicationApi applicationApi;

Expand Down Expand Up @@ -74,6 +79,19 @@ public void stopEffector(RunningAppContext app, String entityId) {
executeEffector(effectorTemplate);
}

public void restartEffector(RunningAppContext app, String entityId) {
EffectorTemplate effectorTemplate =
new EffectorTemplate(app, entityId, RESTART_EFFECTOR_NAME, getRestartBody());
executeEffector(effectorTemplate);
}


public void releaseEffector(RunningAppContext app, String entityId) {
EffectorTemplate effectorTemplate =
new EffectorTemplate(app, entityId, STOP_EFFECTOR_NAME, getReleaseBody());
executeEffector(effectorTemplate);
}

private void executeEffector(EffectorTemplate effectorTemplate) {
try {
restBrooklynClient.executeEffector(effectorTemplate);
Expand All @@ -87,6 +105,29 @@ private void executeEffector(EffectorTemplate effectorTemplate) {
}

public String getStopBody() {
try {
return objectMapper.writeValueAsString(MutableMap.of(
STOP_MACHINE_MODE, STOP_PROCESS_MODE_NEVER,
STOP_PROCESS_MODE, STOP_MACHINE_IF_NOT_STOPPED
));
} catch (Exception e) {
throw new RuntimeException("STOP params can not be generated", e);
}
}
public String getRestartBody() {
try {
return objectMapper.writeValueAsString(MutableMap.of(

));
} catch (Exception e) {
throw new RuntimeException("STOP params can not be generated", e);
}
}




public String getReleaseBody() {
try {
return objectMapper.writeValueAsString(MutableMap.of(STOP_MACHINE_MODE, STOP_MACHINE_IF_NOT_STOPPED));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
public enum BrooklynEntityStatus {

RUNNING,
STARTING,
ON_FIRE,
CREATED,
STOPPED

STOPPED,
STOPPING

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.scenic.orchestrator.core.deployer.dto;

import static java.util.Arrays.stream;

import java.util.List;
import java.util.Map;

import org.apache.brooklyn.rest.domain.LocationSummary;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.web.client.RestTemplate;

/**
Expand Down Expand Up @@ -71,10 +76,55 @@ public Boolean isUp() {
return brooklynRestTemplate.getForEntity(sensorlink + IS_UP_SENSOR, Boolean.class).getBody();
}

public BrooklynEntityStatus status() {
public BrooklynEntityStatus getStatus() {
return brooklynRestTemplate.getForEntity(sensorlink + STATUS_SENSOR, BrooklynEntityStatus.class).getBody();
}

public String getSensor(String sensorName){
return brooklynRestTemplate.getForEntity(sensorlink +"/" +sensorName, String.class).getBody();
}

public boolean hasSshLiveCloudResources(){
return stream(brooklynRestTemplate.getForEntity(getLinks().get("locations"), LocationSummary[].class).getBody())
.anyMatch(this::hasSshResources);
}

private boolean hasSshResources(LocationSummary l){
return l.getType().toLowerCase().contains("ssh");
}

public boolean isInPaas(){
return stream(brooklynRestTemplate.getForEntity(getLinks().get("locations"), LocationSummary[].class).getBody())
.anyMatch(l -> l.getType().toLowerCase().contains("cloudfoundrypaaslocation"));
}

public static class LocationSummary{

String id;
String type;

public LocationSummary(){
this.id=null;
this.type=null;
}

public String getId(){
return id;
}

public String getType(){
return type;
}

public String setId(String id){
return this.id=id;
}

public String getType(String type){
return this.type=type;
}
}

/*"id": "nDQUMK7J",
"name": "SoftcareWS",
"type": "org.apache.brooklyn.entity.webapp.tomcat.TomcatServer",
Expand All @@ -97,6 +147,4 @@ public BrooklynEntityStatus status() {
"catalog": "/v1/catalog/entities/org.apache.brooklyn.entity.webapp.tomcat.TomcatServer/0.9.0"
}
*/


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public enum EntityStatus {
UNAVAILABLE("unavailable"),
STARTED("started"),
STOPPED("stopped"),
FAILED("failed");
FAILED("failed"),
RELEASED("failed"),
;

private final String alias;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public ApplicationStatus build(String appTopology) {
return build(getNodeTemplateNames(appTopology));
}

public ApplicationStatus buildSycn(String appTopology) {
return buildSycn(getNodeTemplateNames(appTopology));
}

public ApplicationStatus build(List<String> entityNames) {
Map<String, EntityStatus> current = new HashMap<>();
Map<String, EntityStatus> target = new HashMap<>();
Expand All @@ -38,6 +42,17 @@ public ApplicationStatus build(List<String> entityNames) {
return new ApplicationStatus(current, target);
}

public ApplicationStatus buildSycn(List<String> entityNames) {
Map<String, EntityStatus> current = new HashMap<>();
Map<String, EntityStatus> target = new HashMap<>();
for (String entityName : entityNames) {
current.put(entityName, EntityStatus.STARTED);
target.put(entityName, EntityStatus.STARTED);
}

return new ApplicationStatus(current, target);
}

private List<String> getNodeTemplateNames(String app) {
final Map<String, Object> obj = yaml.load(app);
return new LinkedList<>(((Map<String, Object>) ((Map<String, Object>) obj.get(TOPOLOGY_TEMPLATE)).get(NODE_TEMPLATES)).keySet());
Expand Down
Loading