* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
+ * Modifications Copyright (C) 2019 IBM.
+ * =============================================================================
* 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
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
-
-
package org.onap.appc.adapter.iaas.impl;
import org.onap.appc.Constants;
import org.onap.appc.adapter.iaas.provider.operation.impl.EvacuateServer;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.encryption.EncryptionTool;
import org.onap.appc.exceptions.APPCException;
import org.onap.appc.util.StructuredPropertyHelper;
import org.onap.appc.util.StructuredPropertyHelper.Node;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
/**
* This class implements the {@link ProviderAdapter} interface. This interface defines the behaviors that our service
* provides.
* The default domain name for authentication
*/
public static final String DEFAULT_DOMAIN_NAME = "Default";
-
- /**
- * The logger to be used
- */
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(ProviderAdapterImpl.class);
/**
* A reference to the adapter configuration object.
*/
private Configuration configuration;
-
/**
* reference to operation factory
*/
- ProviderOperationFactory factory = ProviderOperationFactory.getInstance();
-
+ private ProviderOperationFactory factory;
/**
* A cache of providers that are predefined.
*/
private Map<String /* provider name */, ProviderCache> providerCache;
-
/**
* The username, password, and domain to use for dynamically created connections
*/
private static String DEFAULT_PASS;
private static String DEFAULT_DOMAIN;
-
/**
* This default constructor is used as a work around because the activator wasnt getting called
*/
initialize();
}
-
/**
* This constructor is used primarily in the test cases to bypass initialization of the adapter for isolated,
* disconnected testing
initialize();
}
}
-
/**
* @param props not used
*/
initialize();
}
-
@Override
public Server restartServer(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.RESTART_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Server) op.doOperation(params, context);
}
-
@Override
public Server stopServer(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.STOP_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Server) op.doOperation(params, context);
}
-
@Override
public Server startServer(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.START_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Server) op.doOperation(params, context);
}
-
@Override
public Server rebuildServer(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.REBUILD_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Server) op.doOperation(params, context);
}
-
@Override
public Server terminateServer(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.TERMINATE_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Server) op.doOperation(params, context);
}
-
@Override
public Server evacuateServer(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.EVACUATE_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
// pass this object's reference to EvacuateServer to allow rebuild after evacuate
((EvacuateServer) op).setProvideAdapterRef(this);
return (Server) op.doOperation(params, context);
}
-
@Override
public Server migrateServer(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.MIGRATE_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Server) op.doOperation(params, context);
}
-
@Override
public Server vmStatuschecker(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.VMSTATUSCHECK_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Server) op.doOperation(params, context);
}
-
@Override
public Stack terminateStack(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.TERMINATE_STACK);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Stack) op.doOperation(params, context);
}
-
@Override
public Stack snapshotStack(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.SNAPSHOT_STACK);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Stack) op.doOperation(params, context);
}
-
@Override
public Stack restoreStack(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.RESTORE_STACK);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Stack) op.doOperation(params, context);
}
-
@Override
public Server lookupServer(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.LOOKUP_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Server) op.doOperation(params, context);
}
-
@Override
public Image createSnapshot(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
IProviderOperation op = factory.getOperationObject(Operation.SNAPSHOT_SERVICE);
op.setProviderCache(this.providerCache);
- op.setDefaultPass(DEFAULT_PASS);
+ op.setDefaultPassword(DEFAULT_PASS);
op.setDefaultUser(DEFAULT_USER);
op.setDefaultDomain(DEFAULT_DOMAIN);
return (Image) op.doOperation(params, context);
}
-
/**
* Returns the symbolic name of the adapter
*
public String getAdapterName() {
return configuration.getProperty(Constants.PROPERTY_ADAPTER_NAME);
}
-
-
/**
* initialize the provider adapter by building the context cache
*/
private void initialize() {
configuration = ConfigurationFactory.getConfiguration();
-
/*
* Initialize the provider cache for all defined providers. The definition of the providers uses a structured
* property set, where the names form a hierarchical name space (dotted notation, such as one.two.three). Each
* provider2.identity=http://provider2:5000/v2.0 provider2.tenant1.name=someName
* provider2.tenant1.userid=someUser provider2.tenant1.password=somePassword </pre> </p>
*/
+ factory = ProviderOperationFactory.getInstance();
providerCache = new HashMap<>();
Properties properties = configuration.getProperties();
List<Node> providers = StructuredPropertyHelper.getStructuredProperties(properties, Property.PROVIDER);
-
for (Node provider : providers) {
ProviderCache cache = new ProviderCache();
List<Node> providerNodes = provider.getChildren();
DEFAULT_USER = node2.getValue();
break;
case Property.PROVIDER_TENANT_PASSWORD:
- password = node2.getValue();
+ // convert password from Base64 encrypted string prefixed with 'enc:'
+ password = EncryptionTool.getInstance().encrypt(node2.getValue());
DEFAULT_PASS = node2.getValue();
break;
case Property.PROVIDER_TENANT_DOMAIN:
break;
}
}
-
cache.addTenant(null, tenantName, userId, password, domain);
}
}
-
/*
* Add the provider to the set of providers cached
*/
providerCache.put(null, cache);
providerCache.put(cache.getIdentityURL(), cache);
}
-
/*
* Now, initialize the cache for the loaded provider
*/
cache.initialize();
}
}
+ @Override
+ public Server attachVolume(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ IProviderOperation op = factory.getOperationObject(Operation.ATTACHVOLUME_SERVICE);
+ op.setProviderCache(this.providerCache);
+ op.setDefaultPassword(DEFAULT_PASS);
+ op.setDefaultUser(DEFAULT_USER);
+ return (Server) op.doOperation(params, ctx);
+ }
+ @Override
+ public Server dettachVolume(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ IProviderOperation op = factory.getOperationObject(Operation.DETACHVOLUME_SERVICE);
+ op.setProviderCache(this.providerCache);
+ op.setDefaultPassword(DEFAULT_PASS);
+ op.setDefaultUser(DEFAULT_USER);
+ return (Server) op.doOperation(params, ctx);
+ }
+ @Override
+ public Server rebootServer(Map<String, String> params, SvcLogicContext context) throws APPCException {
+ IProviderOperation op = factory.getOperationObject(Operation.REBOOT_SERVICE);
+ op.setProviderCache(this.providerCache);
+ op.setDefaultPassword(DEFAULT_PASS);
+ op.setDefaultUser(DEFAULT_USER);
+ op.setDefaultDomain(DEFAULT_DOMAIN);
+ return (Server) op.doOperation(params, context);
+ }
}