Search in sources :

Example 1 with FileSystemParam

use of com.emc.storageos.model.file.FileSystemParam in project coprhd-controller by CoprHD.

the class FileMirrorServiceApiImpl method createTargetsForExistingSource.

@Override
public TaskResourceRep createTargetsForExistingSource(FileShare fs, Project project, VirtualPool vpool, VirtualArray varray, TaskList taskList, String task, List<Recommendation> recommendations, VirtualPoolCapabilityValuesWrapper vpoolCapabilities) throws InternalException {
    List<FileShare> fileList = null;
    List<FileShare> fileShares = new ArrayList<FileShare>();
    FileSystemParam fsParams = new FileSystemParam();
    fsParams.setFsId(fs.getId().toString());
    fsParams.setLabel(fs.getLabel());
    fsParams.setVarray(fs.getVirtualArray());
    fsParams.setVpool(fs.getVirtualPool());
    TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
    // Prepare the FileShares
    fileList = prepareFileSystems(fsParams, task, taskList, project, tenant, null, varray, vpool, recommendations, vpoolCapabilities, false);
    fileShares.addAll(fileList);
    // prepare the file descriptors
    final List<FileDescriptor> fileDescriptors = prepareFileDescriptors(fileShares, vpoolCapabilities, null);
    final FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
    try {
        // Execute the create mirror copies of fileshare!!!
        controller.createTargetsForExistingSource(fs.getId().toString(), fileDescriptors, task);
    } catch (InternalException e) {
        _log.error("Controller error when creating mirror filesystems", e);
        failFileShareCreateRequest(task, taskList, fileShares, e.getMessage());
        throw e;
    } catch (Exception e) {
        _log.error("Controller error when creating mirror filesystems", e);
        failFileShareCreateRequest(task, taskList, fileShares, e.getMessage());
        throw e;
    }
    return taskList.getTaskList().get(0);
}
Also used : FileSystemParam(com.emc.storageos.model.file.FileSystemParam) FileOrchestrationController(com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController) ArrayList(java.util.ArrayList) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FileShare(com.emc.storageos.db.client.model.FileShare) FileDescriptor(com.emc.storageos.fileorchestrationcontroller.FileDescriptor) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 2 with FileSystemParam

use of com.emc.storageos.model.file.FileSystemParam in project coprhd-controller by CoprHD.

the class FileMirrorServiceApiImpl method assignFilePolicyToFileSystem.

@Override
public void assignFilePolicyToFileSystem(FileShare fs, FilePolicy filePolicy, Project project, VirtualPool vpool, VirtualArray varray, TaskList taskList, String task, List<Recommendation> recommendations, VirtualPoolCapabilityValuesWrapper vpoolCapabilities) throws InternalException {
    List<FileShare> fileList = null;
    List<FileShare> fileShares = new ArrayList<>();
    FileSystemParam fsParams = new FileSystemParam();
    fsParams.setFsId(fs.getId().toString());
    fsParams.setLabel(fs.getLabel());
    fsParams.setVarray(fs.getVirtualArray());
    fsParams.setVpool(fs.getVirtualPool());
    TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
    // Prepare the FileShares
    fileList = prepareFileSystems(fsParams, task, taskList, project, tenant, null, varray, vpool, recommendations, vpoolCapabilities, false);
    fileShares.addAll(fileList);
    // prepare the file descriptors
    final List<FileDescriptor> fileDescriptors = prepareFileDescriptors(fileShares, vpoolCapabilities, null);
    final FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
    try {
        // Execute the create mirror copies of file share!!!
        controller.assignFilePolicyToFileSystem(filePolicy, fileDescriptors, task);
    } catch (InternalException e) {
        _log.error("Controller error when creating mirror filesystems", e);
        failFileShareCreateRequest(task, taskList, fileShares, e.getMessage());
        throw e;
    } catch (Exception e) {
        _log.error("Controller error when creating mirror filesystems", e);
        failFileShareCreateRequest(task, taskList, fileShares, e.getMessage());
        throw e;
    }
}
Also used : FileSystemParam(com.emc.storageos.model.file.FileSystemParam) FileOrchestrationController(com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController) ArrayList(java.util.ArrayList) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FileShare(com.emc.storageos.db.client.model.FileShare) FileDescriptor(com.emc.storageos.fileorchestrationcontroller.FileDescriptor) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 3 with FileSystemParam

use of com.emc.storageos.model.file.FileSystemParam in project coprhd-controller by CoprHD.

the class InternalApiTest method testFSReleaseUsingInternalClient.

@Test
public void testFSReleaseUsingInternalClient() throws Exception {
    // get tenant
    TenantResponse tenant = rSys.path("/tenant").get(TenantResponse.class);
    Assert.assertNotNull(tenant);
    // create a project to host a normal file system
    ProjectParam projectParam = new ProjectParam();
    projectParam.setName("test-internalapi-" + System.currentTimeMillis());
    ProjectElement projectResp = rSys.path("/tenants/" + tenant.getTenant().toString() + "/projects").post(ProjectElement.class, projectParam);
    Assert.assertNotNull(projectResp);
    // create a normal file system which we can then release
    FileSystemParam fsparam = new FileSystemParam();
    fsparam.setVpool(_cosId);
    fsparam.setLabel("test-internalapi-" + System.currentTimeMillis());
    fsparam.setVarray(_nhId);
    fsparam.setSize("20971520");
    TaskResourceRep taskResp = rSys.path("/file/filesystems").queryParam("project", projectResp.getId().toString()).post(TaskResourceRep.class, fsparam);
    Assert.assertTrue(taskResp != null);
    Assert.assertNotNull(taskResp.getOpId());
    Assert.assertNotNull(taskResp.getResource());
    URI fsId = taskResp.getResource().getId();
    String opId = taskResp.getOpId();
    // get the file system object we just created
    ClientResponse response = rSys.path("/file/filesystems/" + fsId.toString()).get(ClientResponse.class);
    Assert.assertTrue(response != null);
    Assert.assertEquals(200, response.getStatus());
    // wait for for the file system create to complete
    int checkCount = 1200;
    String status;
    do {
        // wait upto ~2 minute for fs creation
        Thread.sleep(100);
        taskResp = rSys.path("/file/filesystems/" + fsId + "/tasks/" + opId).get(TaskResourceRep.class);
        status = taskResp.getState();
    } while (status.equals("pending") && checkCount-- > 0);
    if (!status.equals("ready")) {
        Assert.assertTrue("Fileshare create timed out", false);
    }
    // a normal file system should be present in the bulk results
    BulkIdParam bulkIds = rSys.path("/file/filesystems/bulk").get(BulkIdParam.class);
    Assert.assertNotNull("bulk ids should not be null", bulkIds);
    FileShareBulkRep bulkFileShares = rSys.path("/file/filesystems/bulk").post(FileShareBulkRep.class, bulkIds);
    Assert.assertNotNull("bulk response should not be null", bulkFileShares);
    boolean found = false;
    for (FileShareRestRep fs : bulkFileShares.getFileShares()) {
        if (fs.getId().equals(fsId)) {
            found = true;
        }
    }
    Assert.assertTrue("unable to find public FileShare in the bulk results", found);
    // only token is used in release file system operation and hence
    // setting dummy strings for username and tenant ID do not matter
    StorageOSUser user = new StorageOSUser("dummyUserName", "dummyTeneatId");
    user.setToken(_rootToken);
    FileShareRestRep fileShareResponse = _internalFileClient.releaseFileSystem(fsId, user);
    Assert.assertNotNull(fileShareResponse);
    // after release, the file system should no longer be present in the bulk results
    bulkFileShares = rSys.path("/file/filesystems/bulk").post(FileShareBulkRep.class, bulkIds);
    Assert.assertNotNull("bulk response should not be null", bulkFileShares);
    found = false;
    for (FileShareRestRep fs : bulkFileShares.getFileShares()) {
        if (fs.getId().equals(fsId)) {
            found = true;
        }
    }
    Assert.assertFalse("found internal FileShare in the bulk results", found);
    // undo the release of the file system
    fileShareResponse = _internalFileClient.undoReleaseFileSystem(fsId);
    Assert.assertNotNull(fileShareResponse);
    // release it again
    fileShareResponse = _internalFileClient.releaseFileSystem(fsId, user);
    Assert.assertNotNull(fileShareResponse);
    // delete the file system via the internal api
    FileSystemDeleteParam deleteParam = new FileSystemDeleteParam();
    deleteParam.setForceDelete(false);
    taskResp = _internalFileClient.deactivateFileSystem(fsId, _rootToken, deleteParam);
    Assert.assertNotNull(taskResp);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSystemParam(com.emc.storageos.model.file.FileSystemParam) ProjectParam(com.emc.storageos.model.project.ProjectParam) BulkIdParam(com.emc.storageos.model.BulkIdParam) FileShareBulkRep(com.emc.storageos.model.file.FileShareBulkRep) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) FileShareRestRep(com.emc.storageos.model.file.FileShareRestRep) FileSystemDeleteParam(com.emc.storageos.model.file.FileSystemDeleteParam) URI(java.net.URI) ProjectElement(com.emc.storageos.model.project.ProjectElement) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantResponse(com.emc.storageos.model.tenant.TenantResponse) Test(org.junit.Test)

Example 4 with FileSystemParam

use of com.emc.storageos.model.file.FileSystemParam in project coprhd-controller by CoprHD.

the class ApiTest method checkFSCreate.

private void checkFSCreate(BalancedWebResource user, boolean good, boolean dup) throws Exception {
    FileSystemParam fsparam = new FileSystemParam();
    fsparam.setVpool(_cosFile.getId());
    fsparam.setLabel("test-fs-" + System.currentTimeMillis());
    fsparam.setVarray(_nh);
    fsparam.setSize("20480000");
    if (good) {
        TaskResourceRep resp = user.path("/file/filesystems/").queryParam("project", _testProject.toString()).post(TaskResourceRep.class, fsparam);
        Assert.assertNotNull(resp.getOpId());
        Assert.assertNotNull(resp.getResource());
        _fs = resp.getResource().getId();
        String fsId = _fs.toString();
        String opId = resp.getOpId();
        int checkCount = 1200;
        String status;
        do {
            // wait upto ~2 minute for fs creation
            Thread.sleep(100);
            resp = user.path(String.format("/file/filesystems/%s/tasks/%s", fsId, opId)).get(TaskResourceRep.class);
            status = resp.getState();
        } while (status.equals("pending") && checkCount-- > 0);
        if (!status.equals("ready")) {
            Assert.assertTrue("Fileshare create timed out", false);
        }
        if (dup) {
            ClientResponse response = user.path("/file/filesystems").queryParam("project", _testProject.toString()).post(ClientResponse.class, fsparam);
            Assert.assertEquals(400, response.getStatus());
        }
    } else {
        ClientResponse resp = user.path("/file/filesystems").queryParam("project", _testProject.toString()).post(ClientResponse.class, fsparam);
        Assert.assertEquals(403, resp.getStatus());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSystemParam(com.emc.storageos.model.file.FileSystemParam) TaskResourceRep(com.emc.storageos.model.TaskResourceRep)

Example 5 with FileSystemParam

use of com.emc.storageos.model.file.FileSystemParam in project coprhd-controller by CoprHD.

the class InternalApiTest method testInternalFileService.

@Test
public /**
 * This test exercises only the server side functionaly, not the internal client
 * @throws Exception
 */
void testInternalFileService() throws Exception {
    // create fs
    FileSystemParam fsparam = new FileSystemParam();
    fsparam.setVpool(_cosId);
    fsparam.setLabel("test-internalapi-" + System.currentTimeMillis());
    fsparam.setVarray(_nhId);
    fsparam.setSize("20971520");
    URI path = URI.create(_apiServer).resolve("/internal/file/filesystems");
    WebResource rRoot = _client.resource(path);
    WebResource.Builder rBuilder = _requestHelper.addSignature(rRoot);
    TaskResourceRep resp = _requestHelper.addToken(rBuilder, _rootToken).post(TaskResourceRep.class, fsparam);
    Assert.assertTrue(resp != null);
    Assert.assertNotNull(resp.getOpId());
    Assert.assertNotNull(resp.getResource());
    String fsId = resp.getResource().getId().toString();
    String opId = resp.getOpId();
    // GET filesystem
    path = URI.create(_apiServer).resolve("/internal/file/filesystems/" + fsId);
    rRoot = _client.resource(path);
    rBuilder = _requestHelper.addSignature(rRoot);
    ClientResponse response = _requestHelper.addToken(rBuilder, _rootToken).get(ClientResponse.class);
    Assert.assertTrue(response != null);
    Assert.assertEquals(200, response.getStatus());
    // wait for the create to finish
    path = URI.create(_apiServer).resolve("/internal/file/filesystems/" + fsId + "/tasks/" + opId);
    int checkCount = 1200;
    String status;
    do {
        // wait upto ~2 minute for fs creation
        Thread.sleep(100);
        rRoot = _client.resource(path);
        TaskResourceRep fsResp = _requestHelper.addSignature(rRoot).get(TaskResourceRep.class);
        status = fsResp.getState();
    } while (status.equals("pending") && checkCount-- > 0);
    if (!status.equals("ready")) {
        Assert.assertTrue("Fileshare create timed out", false);
    }
    // export
    path = URI.create(_apiServer).resolve("/internal/file/filesystems/" + fsId + "/exports");
    FileSystemExportParam export = new FileSystemExportParam();
    export.setPermissions("root");
    export.setRootUserMapping("root");
    export.setProtocol("NFS");
    export.setEndpoints(new ArrayList<String>());
    export.getEndpoints().add("www.ford.com");
    rRoot = _client.resource(path);
    rBuilder = _requestHelper.addSignature(rRoot);
    resp = _requestHelper.addToken(rBuilder, _rootToken).post(TaskResourceRep.class, export);
    opId = resp.getOpId();
    // wait for the export to finish
    path = URI.create(_apiServer).resolve("/internal/file/filesystems/" + fsId + "/tasks/" + opId);
    do {
        // wait upto ~2 minute for fs creation
        Thread.sleep(100);
        rRoot = _client.resource(path);
        TaskResourceRep fsResp = _requestHelper.addSignature(rRoot).get(TaskResourceRep.class);
        status = fsResp.getState();
    } while (status.equals("pending") && checkCount-- > 0);
    if (!status.equals("ready")) {
        Assert.assertTrue("Fileshare export timed out", false);
    }
    // unexport
    String unexportPath = String.format("/internal/file/filesystems/%s/exports/%s,%s,%s,%s", fsId, export.getProtocol(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping());
    path = URI.create(_apiServer).resolve(unexportPath);
    rRoot = _client.resource(path);
    rBuilder = _requestHelper.addSignature(rRoot);
    resp = _requestHelper.addToken(rBuilder, _rootToken).delete(TaskResourceRep.class, export);
    opId = resp.getOpId();
    // wait for the unexport to finish
    path = URI.create(_apiServer).resolve("/internal/file/filesystems/" + fsId + "/tasks/" + opId);
    do {
        // wait upto ~2 minute for fs creation
        Thread.sleep(100);
        rRoot = _client.resource(path);
        TaskResourceRep fsResp = _requestHelper.addSignature(rRoot).get(TaskResourceRep.class);
        status = fsResp.getState();
    } while (status.equals("pending") && checkCount-- > 0);
    if (!status.equals("ready")) {
        Assert.assertTrue("Fileshare unexport timed out", false);
    }
    // delete
    path = URI.create(_apiServer).resolve("/internal/file/filesystems/" + fsId + "/deactivate");
    FileSystemDeleteParam deleteParam = new FileSystemDeleteParam();
    deleteParam.setForceDelete(false);
    rRoot = _client.resource(path);
    rBuilder = _requestHelper.addSignature(rRoot);
    resp = _requestHelper.addToken(rBuilder, _rootToken).post(TaskResourceRep.class, deleteParam);
    Assert.assertTrue(resp != null);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSystemExportParam(com.emc.storageos.model.file.FileSystemExportParam) FileSystemParam(com.emc.storageos.model.file.FileSystemParam) WebResource(com.sun.jersey.api.client.WebResource) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) FileSystemDeleteParam(com.emc.storageos.model.file.FileSystemDeleteParam) URI(java.net.URI) Test(org.junit.Test)

Aggregations

FileSystemParam (com.emc.storageos.model.file.FileSystemParam)7 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 FileSystemDeleteParam (com.emc.storageos.model.file.FileSystemDeleteParam)3 URI (java.net.URI)3 Test (org.junit.Test)3 FileShare (com.emc.storageos.db.client.model.FileShare)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 FileDescriptor (com.emc.storageos.fileorchestrationcontroller.FileDescriptor)2 FileOrchestrationController (com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController)2 FileSystemExportParam (com.emc.storageos.model.file.FileSystemExportParam)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 WebResource (com.sun.jersey.api.client.WebResource)2 ArrayList (java.util.ArrayList)2 BulkIdParam (com.emc.storageos.model.BulkIdParam)1 FileShareBulkRep (com.emc.storageos.model.file.FileShareBulkRep)1 FileShareRestRep (com.emc.storageos.model.file.FileShareRestRep)1 ProjectElement (com.emc.storageos.model.project.ProjectElement)1 ProjectParam (com.emc.storageos.model.project.ProjectParam)1