Moises Gamio
Moises Gamio Software Engineer. Comprehensive experience in all phases of the software development lifecycle for several economic sectors.

File Access Denied in a Cluster with Load Balancing

File Access Denied in a Cluster with Load Balancing

Load balancing is a process that routes network traffic to a group of backend servers, also known as a server pool. A load balancer is responsible for distributing incoming requests to a collection of application servers.

Load balancers help solve problems of server performance, high availability and scalability in distributed systems.

Application Server

Application server refers to the process that provides the functions required to support and host user applications. For example, in Websphere, an application server runs Java language-based applications.

Clustering

A cluster is a group of servers that are managed together. For example, in the WebSphere Application Server, all application servers processes are running the same set of enterprise applications, and the workload capacity is distributed between these servers.

java interview

The benefits of building a cluster are:

  • Scalability enables enterprise applications to handle an increase in load volumes properly and achieve better throughput by using more infrastructure resources.

  • High availability means enterprise applications can continue to process work and avoid impacts in the occurrence of failure of one or several components.

When a Cluster shares a File Server

We want to deploy a Java WebClient to retrieve image objects from an external API and store it in an internal file server.

The Java WebClient is deployed in a cluster with two application servers.

loadBalancing and FileServer.

The cluster uses a load balancer to delegate a specific task to one of its servers in a randomized order. A load-balancing algorithm is a load balancer’s logic to distribute network traffic between servers.

The first time a user requests the execution of the Java WebClient, the load balancer delegates the task to the first application server, for example.

The Java WebClient stores some image files in a directory, and the AppServer1 server owns those files.

1
2
U:\imagesFromApi\image1.jpg (owner AppServer1)
U:\imagesFromApi\image2.jpg (owner AppServer1)

One week after, the Java WebClient is requested again, but it needs to execute the following code to delete an image file on the internal file server if the same image was deleted on the external API.

1
2
3
4
5
6
7
8
public void deleteFile(String fileName) throws Exception {
  try {
    File file = new File(OUTPUT_FILE_LOCATION + fileName);
    file.delete(); 
  } catch (Exception e) {
    logger.error("Exception in deleteFile " + e.getMessage());
  }
}

But this second time, the load balancer delegates the execution of the task to the second application server - AppServer2. Then, the java client throws an error.

1
Access is denied

The Java WebClient cannot delete files that another user created.

We cannot change the permissions of a file from within a Java program as we can on Linux systems - chmod command.

Possible Solutions

  • Configure only one user account on application servers and give it full access control - hardware configuration.
  • Deploy the Java WebClient in only one server.

Now any application server in the cluster can create or delete any file on the file server.