/* * Copyright 2000-2015 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.client; import com.intellij.openapi.diagnostic.Logger; import java.util.Collection; import jetbrains.buildServer.clouds.CloudInstanceUserData; import jetbrains.buildServer.clouds.vmware.settings.VMImageInfo; import jetbrains.buildServer.clouds.vmware.vmrun.VMRun; import jetbrains.buildServer.clouds.vmware.vmrun.VMRunParameters; import org.jetbrains.annotations.NotNull; /** * @author Eugene Petrenko * Created: 09.12.2009 20:10:04 */ public class LoggingVMRun implements VMRun { private static final Logger LOG = Logger.getInstance(LoggingVMRun.class.getName()); private final VMRun myRun; public LoggingVMRun(final VMRun run) { myRun = run; } @NotNull public Collection getRunningImages() { LOG.info("Pinging running instances..."); final Collection infoCollection = myRun.getRunningImages(); LOG.info("Found " + infoCollection.size() + " running instances"); return infoCollection; } @NotNull public Collection getLocalImages() { LOG.info("Computing local images..."); final Collection infoCollection = myRun.getLocalImages(); LOG.info("Found " + infoCollection.size() + " local images"); return infoCollection; } public int getAllowedMachinesToRun() { return myRun.getAllowedMachinesToRun(); } public int getVersion(final int serverVersion) { final int clientVersion = myRun.getVersion(serverVersion); LOG.info("Server version is: " + serverVersion); LOG.info("Client version is: " + clientVersion); if (clientVersion != serverVersion) { LOG.warn("\r\n" + "\r\n" + "-------------------\r\n" + " Client version is " + clientVersion + ", server version is " + serverVersion + ".\r\n" + " Upgrade is required.\r\n" + "-------------------"+ "\r\n" + "\r\n"); } return clientVersion; } @NotNull public String getLocationId() { return myRun.getLocationId(); } @NotNull public String getHostName() { return myRun.getHostName(); } public void startMachine(@NotNull final VMRunParameters instance, @NotNull final CloudInstanceUserData data) { LOG.info("Starting new virtual machine: image: " + instance.getImageId()); myRun.startMachine(instance, data); } public void terminateMachine(@NotNull final VMImageInfo image) { LOG.info("Stopping new virtual machine: image: " + image.getId()); myRun.terminateMachine(image); } }