* 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.
*/
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;
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;
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);
}
}
} 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) {
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());
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))) {
logger.error(msg);
throw new TimeoutException(msg);
}
-
+
rc.reset();
logger.info("Reboot server status flag --> " + status);
return status;
* 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.
*/
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, "");
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);
+ }
+ }
}