diff options
2 files changed, 49 insertions, 17 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebootServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebootServer.java index a0f09b56b..b6cf8cc58 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebootServer.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/RebootServer.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +24,9 @@ */ package org.onap.appc.adapter.iaas.provider.operation.impl; -import static org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation.REBOOT_SERVICE; import static org.onap.appc.adapter.utils.Constants.ADAPTER_NAME; - import java.util.Map; import java.util.concurrent.TimeoutException; - -import org.onap.appc.configuration.Configuration; import org.glassfish.grizzly.http.util.HttpStatus; import org.onap.appc.Constants; import org.onap.appc.adapter.iaas.ProviderAdapter; @@ -38,6 +36,7 @@ import org.onap.appc.adapter.iaas.impl.RequestFailedException; import org.onap.appc.adapter.iaas.impl.VMURL; import org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation; import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation; +import org.onap.appc.configuration.Configuration; import org.onap.appc.configuration.ConfigurationFactory; import org.onap.appc.exceptions.APPCException; import org.onap.appc.i18n.Msg; @@ -57,13 +56,11 @@ public class RebootServer extends ProviderServerOperation { private static final Configuration config = ConfigurationFactory.getConfiguration(); private static final Integer NO_OF_ATTEMPTS=30; private static final Integer RETRY_INTERVAL=10; - private static final int MILLI_SECONDS=1000; @Override protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException { setMDC(Operation.REBOOT_SERVICE.toString(), "App-C IaaS Adapter:rebootServer", ADAPTER_NAME); - // logOperation(Msg.REBOOT_SERVER, params, context); return rebootServer(params, context); } @@ -111,8 +108,6 @@ public class RebootServer extends ProviderServerOperation { } } catch (ResourceNotFoundException | StateException ex) { - String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, ex, ex.getClass().getSimpleName(), - REBOOT_SERVICE.toString(), vmUrl, tenantName); logger.info(ex.getMessage()); ctx.setAttribute("REBOOT_STATUS", "FAILURE"); if (ex instanceof ResourceNotFoundException) { @@ -121,8 +116,6 @@ public class RebootServer extends ProviderServerOperation { doFailure(requestContext, HttpStatus.CONFLICT_409, ex.getMessage()); } } catch (Exception ex) { - String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, ex, ex.getClass().getSimpleName(), - REBOOT_SERVICE.toString(), vmUrl, tenantName); logger.info(ex.getMessage()); ctx.setAttribute("REBOOT_STATUS", "FAILURE"); doFailure(requestContext, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.getMessage()); @@ -139,7 +132,6 @@ public class RebootServer extends ProviderServerOperation { Context context = server.getContext(); String msg; boolean status = false; - long endTime = System.currentTimeMillis() + (timeout * MILLI_SECONDS); while (rc.attempt()) { server.waitForStateChange(pollInterval, timeout, desiredStates); if ((server.getStatus().equals(Server.Status.RUNNING)) || (server.getStatus().equals(Server.Status.READY))) { @@ -167,7 +159,7 @@ public class RebootServer extends ProviderServerOperation { logger.error(msg); throw new TimeoutException(msg); } - + rc.reset(); logger.info("Reboot server status flag --> " + status); return status; diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebootServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebootServer.java index 33ce7c2cc..876201fa6 100644 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebootServer.java +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/provider/operation/impl/TestRebootServer.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,23 +24,26 @@ */ package org.onap.appc.adapter.iaas.provider.operation.impl; -import static org.mockito.Mockito.inOrder; import org.onap.appc.adapter.iaas.ProviderAdapter; -import org.junit.Assert; +import org.onap.appc.adapter.iaas.impl.RequestContext; +import org.onap.appc.adapter.iaas.impl.RequestFailedException; +import org.onap.appc.configuration.ConfigurationFactory; import org.junit.Test; -import org.mockito.InOrder; +import org.mockito.Mockito; import org.onap.appc.exceptions.APPCException; import com.att.cdp.exceptions.ZoneException; +import com.att.cdp.zones.Context; import com.att.cdp.zones.model.Server; import com.att.cdp.zones.model.Server.Status; +import com.att.cdp.zones.model.Tenant; import static org.junit.Assert.assertEquals; +import java.util.Properties; public class TestRebootServer { @Test - public void should_returnNullAsServer() throws ZoneException,APPCException { + public void should_returnNullAsServer() throws ZoneException,APPCException { MockGenerator mg = new MockGenerator(Status.SUSPENDED); - Server server = mg.getServer(); RebootServer rbs = new RebootServer(); mg.getParams().put(ProviderAdapter.PROPERTY_INSTANCE_URL, "url1"); mg.getParams().put(ProviderAdapter.REBOOT_TYPE, ""); @@ -48,4 +53,39 @@ public class TestRebootServer { assertEquals("SUCCESS", mg.getParams().get("REBOOT_STATUS")); } + @Test + public void rebootServerTest() throws ZoneException,APPCException, RequestFailedException { + MockGenerator mg = new MockGenerator(Status.RUNNING); + SubclassRebootServer rbs = Mockito.spy(new SubclassRebootServer()); + mg.getParams().put(ProviderAdapter.PROPERTY_INSTANCE_URL, getURL()); + mg.getParams().put(ProviderAdapter.REBOOT_TYPE, "HARD"); + mg.getParams().put("REBOOT_STATUS", "SUCCESS"); + Tenant tenant = new Tenant(); + tenant.setName("TENANT_NAME"); + mg.getContext().setTenant(tenant); + Mockito.doReturn(mg.getContext()).when(rbs).getContext(Mockito.any(RequestContext.class), Mockito.anyString(), + Mockito.anyString()); + Mockito.doReturn(mg.getServer()).when(rbs).lookupServer(Mockito.any(RequestContext.class), Mockito.any(Context.class), + Mockito.anyString()); + rbs.setProviderCache(mg.getProviderCacheMap()); + rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext()); + assertEquals("SUCCESS", mg.getParams().get("REBOOT_STATUS")); + } + + private String getURL() { + Properties props = ConfigurationFactory.getConfiguration().getProperties(); + return String.format("http://%s:%s/v2/%s/servers/%s", props.getProperty("test.ip"), props.getProperty("test.port"), + "3b3d77e0-a79d-4c10-bfac-1b3914af1a14", "3b3d77e0-a79d-4c10-bfac-1b3914af1a14"); + } + + class SubclassRebootServer extends RebootServer { + @Override + public Context getContext(RequestContext rc, String selfLinkURL, String providerName) { + return super.getContext(rc, selfLinkURL, providerName); + } + @Override + public Server lookupServer(RequestContext rc, Context context, String id) throws ZoneException, RequestFailedException { + return super.lookupServer(rc, context, id); + } + } } |