/* * Copyright 2000-2011 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jetbrains.buildServer.clouds.vmware; import java.util.Date; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import jetbrains.buildServer.clouds.CloudErrorInfo; import jetbrains.buildServer.clouds.CloudInstance; import jetbrains.buildServer.clouds.InstanceStatus; import jetbrains.buildServer.serverSide.AgentDescription; import org.jetbrains.annotations.NotNull; /** * @author Eugene Petrenko * Created: 07.12.2009 20:28:18 */ public class VMWareInstance extends ErrorHolder implements CloudInstance { private final Date myStarted = new Date(); private final String myInstanceId; private final String myInstanceName; private final VMWareImage myImage; private final AtomicReference myStatus = new AtomicReference(InstanceStatus.SCHEDULED_TO_START); public VMWareInstance(final VMWareImage image, final String instanceId, final String instanceName) { myImage = image; myInstanceId = instanceId; myInstanceName = instanceName; setStatus(InstanceStatus.SCHEDULED_TO_START); } @NotNull public String getInstanceId() { return myInstanceId; } @NotNull public String getName() { return myInstanceName; } @NotNull public String getAgentName() { return "WM-" + myImage.getName(); } @NotNull public String getImageId() { return myImage.getId(); } @NotNull public VMWareImage getImage() { return myImage; } @NotNull public Date getStartedTime() { return myStarted; } public String getNetworkIdentity() { return null; } @NotNull public InstanceStatus getStatus() { final CloudErrorInfo er = getErrorInfo(); return er != null ? InstanceStatus.ERROR : myStatus.get(); } public void setStatus(@NotNull InstanceStatus status) { myStatus.set(status); } public boolean containsAgent(@NotNull final AgentDescription agent) { final Map ps = agent.getDefinedParameters(); final String agebtImageId = ps.get(VMWareConstants.WM_IMAGE_ID); final String agentInstanceId = ps.get(VMWareConstants.WM_INSTANCE_ID); return getImageId().equals(agebtImageId) && getInstanceId().equals(agentInstanceId); } public void dispose() { //NOP } }