class MsoTenantAdapterImpl implements MsoTenantAdapter {

    @Override
    public void createTenant(String cloudSiteId, String tenantName, Map<String, String> metadata, Boolean failIfExists,
            Boolean backout, MsoRequest msoRequest, Holder<String> tenantId, Holder<TenantRollback> rollback)
            throws TenantException {

        logger.debug("Call to MSO createTenant adapter. Creating Tenant: {} in {}", tenantName, cloudSiteId);

        // Start building up rollback object
        TenantRollback tenantRollback = new TenantRollback();
        tenantRollback.setCloudId(cloudSiteId);
        tenantRollback.setMsoRequest(msoRequest);

        MsoTenantUtils tUtils;
        try {
            tUtils = tFactory.getTenantUtils(cloudSiteId);
        } catch (MsoCloudSiteNotFound me) {
            logger.error("{} {} no implementation found for {}: ", MessageEnum.RA_CREATE_TENANT_ERR,
                    ErrorCode.DataError.getValue(), cloudSiteId, me);
            throw new TenantException(me);
        }

        MsoTenant newTenant = null;
        String newTenantId;
        try {
            newTenant = tUtils.queryTenantByName(tenantName, cloudSiteId);
        } catch (MsoException me) {
            logger.error(OPENSTACK_COMMUNICATE_EXCEPTION_MSG, MessageEnum.RA_CREATE_TENANT_ERR,
                    ErrorCode.DataError.getValue(), me);
            throw new TenantException(me);
        }
        if (newTenant == null) {
            if (backout == null)
                backout = true;
            try {
                newTenantId = tUtils.createTenant(tenantName, cloudSiteId, metadata, backout.booleanValue());
            } catch (MsoException me) {
                logger.error(OPENSTACK_COMMUNICATE_EXCEPTION_MSG, MessageEnum.RA_CREATE_TENANT_ERR,
                        ErrorCode.DataError.getValue(), me);
                throw new TenantException(me);
            }
            tenantRollback.setTenantId(newTenantId);
            tenantRollback.setTenantCreated(true);
            logger.debug("Tenant {} successfully created with ID {}", tenantName, newTenantId);
        } else {
            if (failIfExists != null && failIfExists) {
                logger.error("{} {} CreateTenant: Tenant {} already exists in {} ", MessageEnum.RA_TENANT_ALREADY_EXIST,
                        ErrorCode.DataError.getValue(), tenantName, cloudSiteId);
                throw new TenantAlreadyExists(tenantName, cloudSiteId, newTenant.getTenantId());
            }

            newTenantId = newTenant.getTenantId();
            tenantRollback.setTenantCreated(false);
            logger.debug("Tenant {} already exists with ID {}", tenantName, newTenantId);
        }


        tenantId.value = newTenantId;
        rollback.value = tenantRollback;
        return;
    }

}