本文整理了Java中io.cattle.platform.core.model.Instance.getState()
方法的一些代码示例,展示了Instance.getState()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instance.getState()
方法的具体详情如下:
包路径:io.cattle.platform.core.model.Instance
类名称:Instance
方法名:getState
[英]Getter for cattle.instance.state
.
[中]cattle.instance.state
的Getter。
代码示例来源:origin: rancher/cattle
@Override
public boolean evaluate(Instance obj) {
return !UNALLOCATED_WAIT_STATES.contains(obj.getState());
}
代码示例来源:origin: rancher/cattle
@Override
public void stop() {
if (instance != null && instance.getState().equals(InstanceConstants.STATE_RUNNING)) {
context.objectProcessManager.scheduleProcessInstanceAsync(InstanceConstants.PROCESS_STOP, instance,
null);
}
}
代码示例来源:origin: rancher/cattle
@Override
public boolean isTransitioning() {
if (this.instance == null) {
return false;
}
return context.objectMetaDataManager.isTransitioningState(Instance.class, this.instance.getState());
}
}
代码示例来源:origin: rancher/cattle
@Override
public boolean isError() {
return this.instance != null && (ERROR_STATES.contains(this.instance.getState()) || this.instance.getRemoved() != null);
}
代码示例来源:origin: rancher/cattle
public static void removeInstance(Instance instance, ObjectProcessManager objectProcessManager) {
HashMap<String, Object> data = new HashMap<String, Object>();
data.put(ServiceConstants.PROCESS_DATA_SERVICE_RECONCILE, true);
if (!(instance.getState().equals(CommonStatesConstants.REMOVED) || instance.getState().equals(
CommonStatesConstants.REMOVING))) {
try {
objectProcessManager.scheduleStandardProcessAsync(StandardProcess.REMOVE, instance,
data);
} catch (ProcessCancelException e) {
objectProcessManager.scheduleProcessInstanceAsync(InstanceConstants.PROCESS_STOP,
instance, ProcessUtils.chainInData(data,
InstanceConstants.PROCESS_STOP, InstanceConstants.PROCESS_REMOVE));
}
}
}
代码示例来源:origin: rancher/cattle
@Override
protected boolean isStartedImpl() {
if (startOnce) {
return isStartedOnce();
}
return context.objectManager.reload(this.instance).getState().equalsIgnoreCase(InstanceConstants.STATE_RUNNING);
}
代码示例来源:origin: rancher/cattle
@Override
public DeploymentUnitInstance startImpl() {
if (instance != null && InstanceConstants.STATE_STOPPED.equals(instance.getState())) {
context.activityService.instance(instance, "start", "Starting stopped instance", ActivityLog.INFO);
context.objectProcessManager.scheduleProcessInstanceAsync(
InstanceConstants.PROCESS_START, instance, null);
}
return this;
}
代码示例来源:origin: rancher/cattle
protected boolean isStartOnce(Instance instance) {
Map<String, Object> labels = DataAccessor
.fieldMap(instance, InstanceConstants.FIELD_LABELS);
boolean startOnce = false;
List<String> stoppedStates = Arrays.asList(InstanceConstants.STATE_STOPPED, InstanceConstants.STATE_STOPPING);
if (labels.containsKey(SystemLabels.LABEL_SERVICE_CONTAINER_START_ONCE)) {
startOnce = Boolean.valueOf(((String) labels
.get(SystemLabels.LABEL_SERVICE_CONTAINER_START_ONCE)))
&& instance.getStartCount() != null && instance.getStartCount() >= 1L
&& stoppedStates.contains(instance.getState());
}
return startOnce;
}
代码示例来源:origin: rancher/cattle
@Override
public boolean evaluate(Instance obj) {
if ((startOnce && ERROR_STATES.contains(obj.getState()))
|| obj.getRemoved() != null
|| (!startOnce && BAD_ALLOCATING_STATES.contains(obj.getState()))) {
String error = TransitioningUtils.getTransitioningError(obj);
String message = "Bad instance [" + key(instance) + "] in state [" + obj.getState() + "]";
if (StringUtils.isNotBlank(error)) {
message = message + ": " + error;
}
throw new RuntimeException(message);
}
return context.objectManager.find(InstanceHostMap.class, INSTANCE_HOST_MAP.INSTANCE_ID,
instance.getId()).size() > 0;
}
代码示例来源:origin: rancher/cattle
protected boolean isStartedOnce() {
List<String> validStates = Arrays.asList(InstanceConstants.STATE_STOPPED, InstanceConstants.STATE_STOPPING,
InstanceConstants.STATE_RUNNING);
return validStates.contains(context.objectManager.reload(this.instance).getState())
&& context.objectManager.find(InstanceHostMap.class, INSTANCE_HOST_MAP.INSTANCE_ID,
instance.getId()).size() > 0;
}
代码示例来源:origin: rancher/cattle
@Override
public void run() {
final List<String> healthyStates = Arrays.asList(HealthcheckConstants.HEALTH_STATE_HEALTHY,
HealthcheckConstants.HEALTH_STATE_UPDATING_HEALTHY);
List<? extends Instance> instancesToCheck = getInstancesToCheckForHealth(service, strategy);
for (final Instance instance : instancesToCheck) {
if (instance.getState().equalsIgnoreCase(InstanceConstants.STATE_RUNNING)) {
resourceMntr.waitFor(instance,
new ResourcePredicate<Instance>() {
@Override
public boolean evaluate(Instance obj) {
boolean healthy = instance.getHealthState() == null
|| healthyStates.contains(obj.getHealthState());
if (!healthy) {
stateCheck(service, currentProcess);
}
return healthy;
}
@Override
public String getMessage() {
return "healthy";
}
});
}
}
}
});
代码示例来源:origin: rancher/cattle
@Override
public DeploymentUnitInstance waitForStartImpl() {
this.waitForAllocate();
instance = context.resourceMonitor.waitForNotTransitioning(instance);
if (!((startOnce && isStartedOnce()) || (InstanceConstants.STATE_RUNNING.equals(instance.getState())))) {
String error = TransitioningUtils.getTransitioningError(instance);
String message = String.format("Container should have been running but is in %s state. Check logs for more information.", instance.getState());
if (org.apache.commons.lang3.StringUtils.isNotBlank(error)) {
message = message + ": " + error;
}
throw new InstanceException(message, instance);
}
return this;
}
代码示例来源:origin: rancher/cattle
@Override
public void scheduleCreate() {
if (instance.getState().equalsIgnoreCase(CommonStatesConstants.REQUESTED)) {
context.objectProcessManager.scheduleStandardProcessAsync(StandardProcess.CREATE, instance,
null);
}
if (exposeMap.getState().equalsIgnoreCase(CommonStatesConstants.REQUESTED)) {
context.objectProcessManager.scheduleStandardProcessAsync(StandardProcess.CREATE, exposeMap,
null);
}
}
代码示例来源:origin: rancher/cattle
@Override
public boolean evaluate(Instance obj) {
if (obj.getRemoved() != null) {
throw new TimeoutException("Instance is removed");
}
if (ERROR_STATES.contains(obj.getState())) {
throw new TimeoutException("Instance encountered an error");
}
if (isStartOnce(obj)) {
return START_ONCE_STATES.contains(obj.getState());
}
InstanceHostMap ihm =
objectManager.findAny(InstanceHostMap.class, INSTANCE_HOST_MAP.INSTANCE_ID, obj.getId(), INSTANCE_HOST_MAP.STATE,
CommonStatesConstants.ACTIVE, INSTANCE_HOST_MAP.REMOVED, null);
return ihm != null;
}
代码示例来源:origin: stackoverflow.com
private void waitForInstanceState(List<String> instancesId, InstanceStateName state) {
int numAchievedState = 0;
while (numAchievedState != instancesId.size()) {
try {
Thread.sleep(15000);
} catch (InterruptedException ex) {
Logger.getLogger(AmazonLibrary.class.getName()).log(Level.SEVERE, null, ex);
}
numAchievedState = 0;
DescribeInstancesRequest describeInstance = new DescribeInstancesRequest().withInstanceIds(instancesId);
DescribeInstancesResult describeResult = ec2.describeInstances(describeInstance);
List<Reservation> reservations = describeResult.getReservations();
//different instances might be in different reservation requests
//so we need to traverse those
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
if (instance.getState().getName().equals(state.toString())) {
numAchievedState++;
}
}
}
}
}
代码示例来源:origin: stackoverflow.com
DescribeInstancesRequest dis =new DescribeInstancesRequest();
dis.setInstanceIds(instancesList);
DescribeInstancesResult disresult =ec2.describeInstances(dis);
List <Reservation> list = disresult.getReservations();
System.out.println("-------------- status of instances -------------");
for (Reservation res:list){
List <Instance> instancelist = res.getInstances();
for (Instance instance:instancelist){
System.out.println("Instance Status : "+instance.getState().getName());
List <Tag> t1 =instance.getTags();
for (Tag teg:t1){
System.out.println("Instance Name : "+teg.getValue());
}
}
System.out.println("------------------------------------------------");
}
代码示例来源:origin: stackoverflow.com
public void fetchInstancePublicIP(){
DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceIDs);
DescribeInstancesResult result= ec2.describeInstances(request);
List <Reservation> list = result.getReservations();
for (Reservation res:list) {
List <Instance> instanceList= res.getInstances();
for (Instance instance:instanceList){
System.out.println("Instance Public IP :" + instance.getPublicIpAddress());
System.out.println("Instance Public DNS :" + instance.getPublicDnsName());
System.out.println("Instance State :" + instance.getState());
System.out.println("Instance TAGS :" + instance.getTags());
}
}
}
代码示例来源:origin: stackoverflow.com
public List<String> getRunningInstancesByTags(String tagName, String value) {
List<String> instances = new ArrayList<String>();
for (Reservation reservation : ec2client.describeInstances().getReservations()) {
for (Instance instance : reservation.getInstances()) {
if (!instance.getState().getName().equals(InstanceStateName.Running.toString())) {
continue;
}
for (Tag tag : instance.getTags()) {
if (tag.getKey().equals(tagName) && tag.getValue().equals(value)) {
instances.add(instance.getInstanceId());
}
}
}
}
return instances;
}
代码示例来源:origin: rancher/cattle
@Override
public HandlerResult handle(ProcessState state, ProcessInstance process) {
Instance instance = (Instance) state.getResource();
if (instance.getDeploymentUnitUuid() == null) {
return null;
}
List<Instance> dependants = objectManager.find(Instance.class, INSTANCE.REMOVED, null,
INSTANCE.DEPLOYMENT_UNIT_UUID, instance.getDeploymentUnitUuid(), INSTANCE.NETWORK_CONTAINER_ID,
instance.getId());
if (dependants.isEmpty()) {
return null;
}
List<String> invalidStates = Arrays.asList(CommonStatesConstants.REMOVING, InstanceConstants.STATE_ERROR,
InstanceConstants.STATE_ERRORING, InstanceConstants.STATE_STOPPING, InstanceConstants.STATE_STOPPED);
for (Instance dependant : dependants) {
if (!invalidStates.contains(dependant.getState())) {
objectProcessManager.scheduleProcessInstance(InstanceConstants.PROCESS_STOP, dependant, null);
}
}
return null;
}
}
代码示例来源:origin: rancher/cattle
public void cleanupUpgradedInstances(Service service) {
List<? extends ServiceExposeMap> maps = exposeMapDao.getInstancesSetForUpgrade(service.getId());
List<Instance> waitList = new ArrayList<>();
for (ServiceExposeMap map : maps) {
Instance instance = objectManager.loadResource(Instance.class, map.getInstanceId());
if (instance == null || instance.getRemoved() != null || instance.getState().equals(
CommonStatesConstants.REMOVING)) {
continue;
}
try {
objectProcessMgr.scheduleProcessInstanceAsync(InstanceConstants.PROCESS_REMOVE,
instance, null);
} catch (ProcessCancelException ex) {
// in case instance was manually restarted
objectProcessMgr.scheduleProcessInstanceAsync(InstanceConstants.PROCESS_STOP,
instance, ProcessUtils.chainInData(new HashMap<String, Object>(),
InstanceConstants.PROCESS_STOP, InstanceConstants.PROCESS_REMOVE));
}
}
for (Instance instance : waitList) {
resourceMntr.waitForState(instance, CommonStatesConstants.REMOVED);
}
}
内容来源于网络,如有侵权,请联系作者删除!