JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
17 days ago6 views
👨‍💻Programming

Untitled Page

Ex.2B

index.html

<!DOCTYPE html>
<html>
<head>
    <title>Weather API Integration</title>
</head>

<body>

    <h1>Weather Information</h1>

    <input type="text" id="city" placeholder="Enter city"
           value="Madurai">

    <button onclick="getWeather()">
        Get Weather
    </button>

    <div id="result"></div>

    <script>

        async function getWeather() {

            const city =
                document.getElementById("city").value;

            const API_KEY = "be80a9182c9a35f0bfed709dfc9691ad";

            const url =
                "https://api.openweathermap.org/data/2.5/weather" +
                "?q=" + city +
                "&appid=" + API_KEY +
                "&units=metric";

            try {

                const response = await fetch(url);

                if (!response.ok) {
                    throw new Error(
                        "HTTP Error: " + response.status
                    );
                }

                const data = await response.json();

                document.getElementById("result").innerHTML = `
                    <h2>${data.name}</h2>

                    <p>
                        Temperature:
                        ${data.main.temp} °C
                    </p>

                    <p>
                        Weather:
                        ${data.weather[0].description}
                    </p>

                    <p>
                        Humidity:
                        ${data.main.humidity}%
                    </p>

                    <p>
                        Wind Speed:
                        ${data.wind.speed} m/s
                    </p>
                `;

            }
            catch (error) {

                document.getElementById("result").innerHTML =
                    "Unable to get weather data: "
                    + error.message;
            }
        }

    </script>

</body>
</html>

cmd:

curl.exe -k "https://api.openweathermap.org/data/2.5/weather?q=Madurai&appid=YOUR_API_KEY&units=metric"

-----------------------------------------------------------------------

Ex.2C

node -v
npm -v

mkdir REST

cd REST

npm init -y

npm install express

npm install nodemon

notepad index.js

node index.js

Postman tool

http://localhost:8080/api/books->GET ,put->select body->raw->jsonsame,post->4,delete->4

index.js

const express = require('express');

const app = express();

app.use(express.json());

let books = [
    { title: 'Harry Potter', id: 1 },
    { title: 'Twilight', id: 2 },
    { title: 'Lorien Legacies', id: 3 }
];

// Home route
app.get('/', (req, res) => {
    res.send('REST APIs are so much fun');
});

// GET - Get all books
app.get('/api/books', (req, res) => {
    res.send(books);
});

// GET - Get book by ID
app.get('/api/books/:id', (req, res) => {
    const book = books.find(
        c => c.id === parseInt(req.params.id)
    );

    if (!book) {
        return res.status(404).send(
            "Oops... Can't find what you are looking for!"
        );
    }

    res.send(book);
});

// POST - Add new book
app.post('/api/books', (req, res) => {
    const book = {
        title: req.body.title,
        id: books.length > 0
            ? books[books.length - 1].id + 1
            : 1
    };

    books.push(book);

    res.status(201).send(book);
});

// PUT - Update book
app.put('/api/books/:id', (req, res) => {
    const book = books.find(
        c => c.id === parseInt(req.params.id)
    );

    if (!book) {
        return res.status(404).send('Book not found');
    }

    book.title = req.body.title;

    res.send(book);
});

// DELETE - Delete book
app.delete('/api/books/:id', (req, res) => {
    const id = parseInt(req.params.id);

    const book = books.find(c => c.id === id);

    if (!book) {
        return res.status(404).send('Book not found');
    }

    books = books.filter(c => c.id !== id);

    res.send(book);
});

// Start server
const port = process.env.PORT || 8080;

app.listen(port, () => {
    console.log(`Listening on port ${port}..`);
});

-----------------------------------------------------------------

Ex.3

node -v
npm -v

cd Desktop

npm create vite@latest firebase-lab -- --template react

cd firebase-lab

npm install

open vs code

firebase console

terminal -> npm install firebase

create firebase.js

security->Authentication , database ->firestore

change app.jsx

npm run dev 

firebase.js

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";

const firebaseConfig = {
  apiKey: "YOUR_API_KEY",
  authDomain: "YOUR_AUTH_DOMAIN",
  projectId: "YOUR_PROJECT_ID",
  storageBucket: "YOUR_STORAGE_BUCKET",
  messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
  appId: "YOUR_APP_ID"
};

const app = initializeApp(firebaseConfig);

export const auth = getAuth(app);
export const db = getFirestore(app);

app.jsx

import { useEffect, useState } from "react";
import { auth, db } from "./firebase";

import {
  GoogleAuthProvider,
  signInWithPopup,
  signOut
} from "firebase/auth";

import {
  collection,
  addDoc,
  getDocs,
  updateDoc,
  deleteDoc,
  doc
} from "firebase/firestore";

function App() {

  const [user, setUser] = useState(null);
  const [students, setStudents] = useState([]);

  const [name, setName] = useState("");
  const [age, setAge] = useState("");
  const [department, setDepartment] = useState("");

  // GOOGLE LOGIN
  const login = async () => {
    const provider = new GoogleAuthProvider();

    try {
      const result = await signInWithPopup(auth, provider);
      setUser(result.user);
    } catch (error) {
      console.log(error);
    }
  };

  // LOGOUT
  const logout = async () => {
    await signOut(auth);
    setUser(null);
  };

  // CREATE
  const addStudent = async () => {

    await addDoc(collection(db, "students"), {
      name: name,
      age: Number(age),
      department: department
    });

    setName("");
    setAge("");
    setDepartment("");

    getStudents();
  };

  // READ
  const getStudents = async () => {

    const querySnapshot = await getDocs(
      collection(db, "students")
    );

    const data = querySnapshot.docs.map((document) => ({
      id: document.id,
      ...document.data()
    }));

    setStudents(data);
  };

  // UPDATE
  const updateStudent = async (id) => {

    await updateDoc(doc(db, "students", id), {
      department: "CSE"
    });

    getStudents();
  };

  // DELETE
  const deleteStudent = async (id) => {

    await deleteDoc(doc(db, "students", id));

    getStudents();
  };

  useEffect(() => {
    getStudents();
  }, []);

  return (
    <div>

      <h1>Student Management System</h1>

      {!user ? (
        <button onClick={login}>
          Login with Google
        </button>
      ) : (
        <div>
          <h3>Welcome {user.displayName}</h3>

          <button onClick={logout}>
            Logout
          </button>
        </div>
      )}

      <hr />

      <h2>Add Student</h2>

      <input
        placeholder="Name"
        value={name}
        onChange={(e) => setName(e.target.value)}
      />

      <input
        placeholder="Age"
        value={age}
        onChange={(e) => setAge(e.target.value)}
      />

      <input
        placeholder="Department"
        value={department}
        onChange={(e) => setDepartment(e.target.value)}
      />

      <button onClick={addStudent}>
        Add Student
      </button>

      <h2>Students</h2>

      <button onClick={getStudents}>
        Refresh
      </button>

      {students.map((student) => (

        <div key={student.id}>

          <p>
            {student.name} | {student.age} | {student.department}
          </p>

          <button onClick={() => updateStudent(student.id)}>
            Update
          </button>

          <button onClick={() => deleteStudent(student.id)}>
            Delete
          </button>

        </div>

      ))}

    </div>
  );
}

export default App;

-------------------------------------------------------

Ex.4 Dropbox

python --version

pip --version

pip install dropbox

dropbox console-> create change permissions   settings ->generate token

mkdir dropbox

cd dropbox

notepad sample.txt

notepad storage.py

python storage.py 

storage.py

import dropbox

ACCESS_TOKEN = "PASTE_YOUR_ACCESS_TOKEN_HERE"

dbx = dropbox.Dropbox(ACCESS_TOKEN)

local_file = "sample.txt"
dropbox_path = "/sample.txt"

with open(local_file, "rb") as f:
    dbx.files_upload(f.read(), dropbox_path, mode=dropbox.files.WriteMode.overwrite)

print("File uploaded successfully.")

print("\nFiles in Dropbox:")

result = dbx.files_list_folder("")

for entry in result.entries:
    print(entry.name)

download_path = "downloaded_sample.txt"

metadata, response = dbx.files_download(dropbox_path)

with open(download_path, "wb") as f:
    f.write(response.content)

print("\nFile downloaded successfully.")
print("Saved as:", download_path)

--------------------------------------------------------

Ex.5

python --version

pip --version

pip install pymongo

python -m notebook

go to mongodb atlas 

Step 1 — Open CMD

Press:

Windows key → type cmd → Enter

You should see something like:

C:\Users\nithy>
Step 2 — Check Python

Type:

python --version

You should get something like:

Python 3.13.x
Step 3 — Check PyMongo

Type:

pip show pymongo

You should see:

Name: pymongo
Version: 4.18.2
Step 4 — Start Python

Type:

python

You will see:

>>>

Now do not type cmd commands. We are inside Python.

Step 5 — Import MongoDB

Type:

from pymongo import MongoClient
Step 6 — Connect to Atlas

Type:

client = MongoClient("YOUR_MONGODB_CONNECTION_STRING")

Use your actual Atlas connection string. Don't share your password here.

Then test:

print(client.admin.command("ping"))

You should get:

{'ok': 1.0}
Step 7 — Select database
db = client["CollegeDB"]
print(db.name)

Output:

CollegeDB
Step 8 — Select collection
students = db["Students"]
print(students.name)

Output:

Students
Step 9 — Insert student
students.insert_one({
    "name": "Nithyasri",
    "roll_no": "670560",
    "department": "Information Technology",
    "year": 3
})

print("Student inserted successfully!")
Step 10 — Display students
for student in students.find():
    print(student)
Step 11 — Find Nithyasri
print(students.find_one({"name": "Nithyasri"}))
Step 12 — Update
students.update_one(
    {"name": "Nithyasri"},
    {"$set": {"year": 4}}
)

print("Student updated successfully!")
Step 13 — Delete a sample student
students.delete_one({"name": "Kavin"})
print("Student deleted successfully!")
Step 14 — Count
print("Total students:", students.count_documents({}))
Step 15 — Exit Python

When finished:

exit()

------------------------------------------------

Ex.6

node -v
npm -v

cd Desktop

npm create vite@latest movie-search -- --template react

cd movie-search

npm install @auth0/auth0-react

change:
main.jsx
app.jsx
app.css

npm run dev

Main.jsx

import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { Auth0Provider } from "@auth0/auth0-react";
import "./index.css";
import App from "./App.jsx";

createRoot(document.getElementById("root")).render(
  <StrictMode>
    <Auth0Provider
      domain="dev-htlfxnfnitddddpr.us.auth0.com"
      clientId="72qLa9k5hjCYpGvaJXEMe32qx353Usrd"
      authorizationParams={{
        redirect_uri: window.location.origin,
      }}
    >
      <App />
    </Auth0Provider>
  </StrictMode>
);

App.jsx

import { useState } from "react";
import { useAuth0 } from "@auth0/auth0-react";
import "./App.css";

function App() {
  const {
    isLoading,
    isAuthenticated,
    loginWithRedirect,
    logout,
  } = useAuth0();

  const [movie, setMovie] = useState("");
  const [results, setResults] = useState([]);
  const [message, setMessage] = useState("");

  // Put your OMDb API key here
  const API_KEY = "YOUR_OMDB_API_KEY";

  const searchMovie = async () => {
    if (!movie.trim()) {
      setMessage("Please enter a movie name");
      setResults([]);
      return;
    }

    setMessage("Searching...");
    setResults([]);

    try {
      const response = await fetch(
        `https://www.omdbapi.com/?apikey=${API_KEY}&s=${encodeURIComponent(movie)}`
      );

      const data = await response.json();

      if (data.Response === "True") {
        setResults(data.Search);
        setMessage(`Found ${data.Search.length} movies`);
      } else {
        setResults([]);
        setMessage(data.Error || "Movie not found");
      }
    } catch (error) {
      console.error(error);
      setResults([]);
      setMessage("Could not connect to movie service");
    }
  };

  if (isLoading) {
    return (
      <div className="loading">
        Loading...
      </div>
    );
  }

  return (
    <div className="app">

      {/* NAVBAR */}
      <nav className="navbar">

        <div className="logo">
          🎬 Movie Search
        </div>

        {!isAuthenticated ? (
          <button
            className="login-btn"
            onClick={() => loginWithRedirect()}
          >
            Log in
          </button>
        ) : (
          <button
            className="login-btn"
            onClick={() =>
              logout({
                logoutParams: {
                  returnTo: window.location.origin,
                },
              })
            }
          >
            Log out
          </button>
        )}

      </nav>

      {/* MAIN */}
      <main className="hero">

        <h1>
          Discover Your Next Favorite
          <br />
          <span>Movie</span>
        </h1>

        <p>
          Search through thousands of movies, view trending movies,
          and explore cinematic masterpieces.
        </p>

        {/* NOT LOGGED IN */}
        {!isAuthenticated && (
          <button
            className="start-btn"
            onClick={() => loginWithRedirect()}
          >
            Log in to Start Searching
          </button>
        )}

        {/* LOGGED IN */}
        {isAuthenticated && (
          <>

            <div className="search-box">

              <input
                type="text"
                placeholder="Search for a movie..."
                value={movie}
                onChange={(e) => setMovie(e.target.value)}
                onKeyDown={(e) => {
                  if (e.key === "Enter") {
                    searchMovie();
                  }
                }}
              />

              <button onClick={searchMovie}>
                Search
              </button>

            </div>

            {message && (
              <p className="message">
                {message}
              </p>
            )}

            <div className="results">

              {results.map((item) => (

                <div
                  className="movie-card"
                  key={item.imdbID}
                >

                  {item.Poster &&
                  item.Poster !== "N/A" ? (
                    <img
                      src={item.Poster}
                      alt={item.Title}
                    />
                  ) : (
                    <div className="no-poster">
                      No Poster
                    </div>
                  )}

                  <div className="movie-info">

                    <h2>{item.Title}</h2>

                    <p>
                      <strong>Year:</strong>{" "}
                      {item.Year}
                    </p>

                    <p>
                      <strong>Type:</strong>{" "}
                      {item.Type}
                    </p>

                    <p>
                      <strong>IMDb ID:</strong>{" "}
                      {item.imdbID}
                    </p>

                  </div>

                </div>

              ))}

            </div>

          </>
        )}

      </main>

    </div>
  );
}

export default App;

App.css

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  background: #0b0f14;
  color: white;
}

.app {
  min-height: 100vh;
  background: #0b0f14;
}

.navbar {
  height: 65px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 35px;
  border-bottom: 1px solid #1d232c;
}

.logo {
  font-size: 18px;
  font-weight: bold;
}

.login-btn {
  background: #635bff;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.login-btn:hover {
  background: #5148e5;
}

.hero {
  min-height: calc(100vh - 65px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 70px 30px;
  text-align: center;
}

.hero h1 {
  font-size: 48px;
  line-height: 1.2;
  margin-bottom: 20px;
}

.hero h1 span {
  color: white;
}

.hero > p {
  max-width: 600px;
  color: #aeb4bd;
  font-size: 16px;
  line-height: 1.6;
  margin-bottom: 30px;
}

.start-btn {
  background: #635bff;
  color: white;
  border: none;
  padding: 14px 25px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
}

.start-btn:hover {
  background: #5148e5;
}

.search-box {
  display: flex;
  width: 550px;
  max-width: 90%;
  margin-top: 10px;
}

.search-box input {
  flex: 1;
  padding: 14px;
  background: #151a21;
  border: 1px solid #303742;
  color: white;
  border-radius: 6px 0 0 6px;
  outline: none;
  font-size: 15px;
}

.search-box input::placeholder {
  color: #7f8792;
}

.search-box button {
  padding: 14px 22px;
  background: #635bff;
  color: white;
  border: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  font-weight: bold;
}

.search-box button:hover {
  background: #5148e5;
}

.message {
  color: #aeb4bd;
  margin-top: 20px;
}

.results {
  width: 100%;
  max-width: 1100px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 25px;
  margin-top: 35px;
}

.movie-card {
  background: #151a21;
  border: 1px solid #252c36;
  border-radius: 10px;
  overflow: hidden;
  text-align: left;
  transition: transform 0.2s;
}

.movie-card:hover {
  transform: translateY(-5px);
}

.movie-card img {
  width: 100%;
  height: 300px;
  object-fit: cover;
  display: block;
}

.no-poster {
  width: 100%;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #202630;
  color: #888;
}

.movie-info {
  padding: 15px;
}

.movie-info h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.movie-info p {
  margin: 6px 0;
  color: #aeb4bd;
  font-size: 14px;
}

.loading {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b0f14;
  color: white;
  font-size: 20px;
}

@media (max-width: 900px) {
  .results {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 650px) {
  .results {
    grid-template-columns: repeat(2, 1fr);
  }

  .hero h1 {
    font-size: 36px;
  }
}

@media (max-width: 450px) {
  .results {
    grid-template-columns: 1fr;
  }
}

---------------------------------------------------------

Ex.8 Hadoop

Hadoop 3.3.6 — Complete Code
1. Update Ubuntu
sudo apt update
2. Install SSH
sudo apt install ssh

If asked:

Do you want to continue? [Y/n]

type:

Y
3. Download Hadoop 3.3.6
wget https://dlcdn.apache.org/hadoop/common/hadoop-3.3.6/hadoop-3.3.6.tar.gz
4. Extract Hadoop
tar -xzf hadoop-3.3.6.tar.gz

Check:

ls
5. Rename Hadoop
mv hadoop-3.3.6 hadoop

Check:

ls
6. Install Java 11

The PDF specifically uses Java 11.

sudo apt install openjdk-11-jdk

Check:

java --version
7. Create Hadoop data folders
cd hadoop
mkdir data
cd data
mkdir -p {datanode,namenode}

Check:

ls

You should get:

datanode
namenode
8. Find Java path
dirname $(dirname $(readlink -f $(which java)))

The PDF expects something like:

/usr/lib/jvm/java-11-openjdk-amd64

9. Find Hadoop path

Go back:

cd ..
pwd

You should have something like:

/home/YOUR_USERNAME/hadoop
10. .bashrc configuration

Open:

gedit ~/.bashrc

Go to the bottom and add:

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export HADOOP_HOME=$HOME/hadoop
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_MAPPED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native"

Save and close.

Then:

source ~/.bashrc

The environment-variable block comes directly from the PDF.

11. Check environment variables
echo $JAVA_HOME

Expected:

/usr/lib/jvm/java-11-openjdk-amd64

Then:

echo $HADOOP_HOME

Expected:

/home/YOUR_USERNAME/hadoop

Then:

hadoop version

You should see:

Hadoop 3.3.6
12. Hadoop configuration

Go to the configuration folder:

cd ~/hadoop/etc/hadoop

Check files:

ls

You should see:

core-site.xml
hdfs-site.xml
mapred-site.xml
yarn-site.xml
hadoop-env.sh
13. Configure hadoop-env.sh

Open:

gedit hadoop-env.sh

Find the Java section and set:

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

Save.

The PDF specifically shows setting JAVA_HOME inside hadoop-env.sh.

14. Configure core-site.xml

Open:

gedit core-site.xml

Inside the <configuration> section, add:

<property>
    <name>fs.defaultFS</name>
    <value>hdfs://localhost:9000</value>
</property>

So the file should contain:

<configuration>

<property>
    <name>fs.defaultFS</name>
    <value>hdfs://localhost:9000</value>
</property>

</configuration>

This is the exact Hadoop configuration shown in your PDF.

15. Configure hdfs-site.xml

Open:

gedit hdfs-site.xml

Inside <configuration>, add:

<property>
    <name>dfs.replication</name>
    <value>3</value>
</property>

<property>
    <name>dfs.name.dir</name>
    <value>/home/YOUR_USERNAME/hadoop/data/namenode</value>
</property>

<property>
    <name>dfs.data.dir</name>
    <value>/home/YOUR_USERNAME/hadoop/data/datanode</value>
</property>
IMPORTANT

Replace:

YOUR_USERNAME

with your actual Ubuntu username.

For example, if your Ubuntu username is nithya:

<property>
    <name>dfs.name.dir</name>
    <value>/home/nithya/hadoop/data/namenode</value>
</property>

<property>
    <name>dfs.data.dir</name>
    <value>/home/nithya/hadoop/data/datanode</value>
</property>

The PDF shows the same three properties, with /home/osboxes/hadoop/... as its example path.

16. Configure mapred-site.xml

Open:

gedit mapred-site.xml

Inside <configuration>, add:

<property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
</property>

Complete file:

<configuration>

<property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
</property>

</configuration>

This is the MapReduce configuration shown in the PDF.

17. Configure yarn-site.xml

Open:

gedit yarn-site.xml

Inside <configuration>, add:

<property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
</property>

<property>
    <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
    <value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>

Complete file:

<configuration>

<property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
</property>

<property>
    <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
    <value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>

</configuration>

These are the properties shown in your PDF.

18. SSH key configuration

Run:

ssh-keygen -t rsa

When it asks:

Enter file in which to save the key:

just press Enter.

When it asks for passphrase:

Enter passphrase:

press Enter.

Again:

Enter same passphrase again:

press Enter.

Then run:

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

Then:

chmod 640 ~/.ssh/authorized_keys

These commands are shown in the PDF.

19. Start Hadoop

First make sure you're in any terminal location.

Run:

start-dfs.sh

The PDF shows:

Starting namenodes on [localhost]
Starting datanodes
Starting secondary namenodes

Then run:

jps

You should see processes similar to:

NameNode
DataNode
SecondaryNameNode
Jps

20. Start YARN

Run:

start-yarn.sh

Then:

jps

Now you should see:

NameNode
DataNode
SecondaryNameNode
ResourceManager
NodeManager
Jps

This is the final running-state check shown in your PDF.

21. Stop Hadoop

When you finish the lab:

stop-yarn.sh

Then:

stop-dfs.sh

The PDF shows these commands for shutting down Hadoop services.

----------------------------------------------------------------------
Ex.8 Hadoop Mani's

Hadoop

sudo apt update
sudo apt install ssh -y
sudo apt install openjdk-11-jdk -y
java -version
cd ~
wget https://archive.apache.org/dist/hadoop/common/hadoop-3.3.6/hadoop-3.3.6.tar.gz
tar -xzf hadoop-3.3.6.tar.gz
mv hadoop-3.3.6 Hadoop
ls ~/Hadoop
nano ~/.bashrc

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export HADOOP_HOME=$HOME/hadoop
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native"

Ctrl + O, Enter, then Ctrl + X.

source ~/.bashrc
echo $JAVA_HOME
nano ~/hadoop/etc/hadoop/hadoop-env.sh

Set the Java line to:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

mkdir -p ~/hadoop/data/namenode
mkdir -p ~/hadoop/data/datanode
ls ~/hadoop/data

nano ~/hadoop/etc/hadoop/core-site.xml

<property>
    <name>fs.defaultFS</name>
    <value>hdfs://localhost:9000</value>
</property>

nano ~/hadoop/etc/hadoop/hdfs-site.xml

<property>
    <name>dfs.replication</name>
    <value>1</value>
</property>

<property>
    <name>dfs.namenode.name.dir</name>
    <value>file:///home/vboxuser/hadoop/data/namenode</value>
</property>

<property>
    <name>dfs.datanode.data.dir</name>
    <value>file:///home/vboxuser/hadoop/data/datanode</value>
</property>

cp ~/hadoop/etc/hadoop/mapred-site.xml.template ~/hadoop/etc/hadoop/mapred-site.xml
nano ~/hadoop/etc/hadoop/mapred-site.xml

<property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
</property>

nano ~/hadoop/etc/hadoop/yarn-site.xml
<property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
</property>

<property>
    <name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
    <value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>

ssh-keygen -t rsa
Your identification has been saved
Your public key has been saved

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
Output: No output if successful.

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

sudo service ssh start
ssh localhost

Expected result: You connect to your own Ubuntu machine. Type exit to return to your original terminal.

hadoop version

hdfs namenode -format
Expected output includes a message similar to:
Storage directory ... has been successfully formatted.

start-dfs.sh
start-yarn.sh

jps
hdfs dfs -mkdir -p /test
hdfs dfs -ls /
Found 1 items
... /test

stop-yarn.sh

--------------------------------------------------------------------------

Ex.9 Parallel Pogramming openMP

PART 1 — MPI
Step 1: Open Ubuntu Terminal

Open your Ubuntu terminal.

Check Python:

python3 --version

If Python is not installed:

sudo apt update
sudo apt install python3

The manual specifically starts the MPI procedure with Python 3 installation.

Step 2: Install MPI

Run:

sudo apt install -y -qq mpich

Wait until installation finishes. This is the MPI environment installation given in your manual.

Check whether MPI is installed:

mpiexec --version

or:

mpirun --version

You should get MPI version information.

Step 3: Install pip

Run:

sudo apt install python3-pip

Then install mpi4py:

pip install mpi4py

Your manual uses mpi4py for Python MPI programming.

If Ubuntu gives an externally-managed-environment error, use:

pip install mpi4py --break-system-packages
Step 4: Create MPI program

Create a folder:

mkdir mpi_lab
cd mpi_lab

Create a Python file:

nano mpi_hello.py

Enter:

from mpi4py import MPI

comm = MPI.COMM_WORLD

rank = comm.Get_rank()
size = comm.Get_size()

print("Hello from process", rank, "of", size)

Save:

Ctrl + O → Enter → Ctrl + X

Step 5: Run MPI program

Run:

mpiexec -n 4 python3 mpi_hello.py

Here:

-n 4 → creates 4 processes
rank → identifies each process
size → total number of processes

Expected output will be similar to:

Hello from process 0 of 4
Hello from process 1 of 4
Hello from process 2 of 4
Hello from process 3 of 4

The order may be different. That's completely normal because the processes execute in parallel.

PART 2 — OpenMP

Your manual then moves to OpenMP and asks you to install the required libraries in Ubuntu and execute multiple sample programs.

OpenMP is generally used with C/C++.

Step 6: Install GCC

Run:

sudo apt update
sudo apt install gcc

Check:

gcc --version
Step 7: Create OpenMP Hello World

Create a folder:

mkdir openmp_lab
cd openmp_lab

Create the program:

nano hello.c

Enter:

#include <stdio.h>
#include <omp.h>

int main()
{
    #pragma omp parallel
    {
        printf("Hello from thread %d\n", omp_get_thread_num());
    }

    return 0;
}

Save:

Ctrl + O → Enter → Ctrl + X

Step 8: Compile OpenMP program

This step is very important.

Use:

gcc -fopenmp hello.c -o hello

Then run:

./hello

You may get:

Hello from thread 0
Hello from thread 1
Hello from thread 2
Hello from thread 3
...

The number of threads depends on your system.

Step 9: Specify number of threads

You can control the number of threads.

For example:

export OMP_NUM_THREADS=4

Then:

./hello

You should get approximately:

Hello from thread 0
Hello from thread 1
Hello from thread 2
Hello from thread 3
PART 3 — Loop-Level Parallelism with Reduction

Your manual's Sample 2 is specifically “Loop level Parallelism with reduction.”

Create:

nano reduction.c

Use:

#include <stdio.h>
#include <omp.h>

int main()
{
    int sum = 0;

    #pragma omp parallel for reduction(+:sum)
    for(int i = 1; i <= 100; i++)
    {
        sum += i;
    }

    printf("Sum = %d\n", sum);

    return 0;
}

Compile:

gcc -fopenmp reduction.c -o reduction

Run:

./reduction

Output:

Sum = 5050
What does reduction do?

Normally, multiple threads modifying the same sum can cause problems.

reduction(+:sum)

allows each thread to calculate its own partial sum and then combines the results.

PART 4 — private

Your manual has Sample 3: Using private.

Create:

nano private.c

Use:

#include <stdio.h>
#include <omp.h>

int main()
{
    int x = 10;

    #pragma omp parallel private(x)
    {
        x = omp_get_thread_num();

        printf("Thread %d: x = %d\n",
               omp_get_thread_num(), x);
    }

    return 0;
}

Compile:

gcc -fopenmp private.c -o private

Run:

./private
Meaning
private(x)

means every thread gets its own copy of x.

PART 5 — firstprivate

Your manual's Sample 4 covers firstprivate.

Create:

nano firstprivate.c

Use:

#include <stdio.h>
#include <omp.h>

int main()
{
    int x = 10;

    #pragma omp parallel firstprivate(x)
    {
        x = x + omp_get_thread_num();

        printf("Thread %d: x = %d\n",
               omp_get_thread_num(), x);
    }

    return 0;
}

Compile:

gcc -fopenmp firstprivate.c -o firstprivate

Run:

./firstprivate
Important difference

private:

New variable → initial value is not copied

firstprivate:

New variable → original value is copied first

Here the original value is:

x = 10

so every thread starts with 10.

PART 6 — lastprivate

Your manual's Sample 5 is Using last private.

Create:

nano lastprivate.c

Use:

#include <stdio.h>
#include <omp.h>

int main()
{
    int x = 0;

    #pragma omp parallel for lastprivate(x)
    for(int i = 0; i < 4; i++)
    {
        x = i;

        printf("Thread %d: x = %d\n",
               omp_get_thread_num(), x);
    }

    printf("Final x = %d\n", x);

    return 0;
}

Compile:

gcc -fopenmp lastprivate.c -o lastprivate

Run:

./lastprivate

The final value will correspond to the value assigned in the last sequential loop iteration.

PART 7 — Critical Section

Your manual's Sample 6 covers the critical section.

Create:

nano critical.c

Use:

#include <stdio.h>
#include <omp.h>

int main()
{
    int count = 0;

    #pragma omp parallel
    {
        #pragma omp critical
        {
            count++;
            printf("Thread %d: count = %d\n",
                   omp_get_thread_num(), count);
        }
    }

    printf("Final count = %d\n", count);

    return 0;
}

Compile:

gcc -fopenmp critical.c -o critical

Run:

./critical
Why critical?

Suppose many threads execute:

count++;

at the same time.

This can cause a race condition.

The:

#pragma omp critical

ensures that only one thread at a time enters that section.

------------------------------------------------------------------

Ex.10 Spark installation

Apache Spark — Complete Ubuntu Steps
STEP 1 — Open Terminal

Press:

Ctrl + Alt + T

You will get a terminal like:

username@ubuntu:~$
STEP 2 — Check Java

Type:

java -version
If Java is installed

You will see something like:

openjdk version ...

Then continue to Step 3.

If Java is not installed

Run:

sudo apt-get update

Then:

sudo apt-get install default-jdk -y

Then check:

java -version

Your PDF starts the Spark setup by checking Java.

STEP 3 — Check Scala

Type:

scala --version
If Scala is installed

You will see the Scala version.

Continue to Step 4.

If Scala is not installed

Run:

sudo apt-get install scala -y

Then:

scala --version

The PDF uses scala --version to verify Scala.

STEP 4 — Go to Downloads

Type:

cd ~/Downloads

Then:

ls

You need the Spark file:

spark-1.6.1-bin-hadoop2.6.tgz

The PDF uses Spark 1.6.1 with Hadoop 2.6.

If the file is already there

Continue to Step 5.

If it is NOT there

Run:

wget https://archive.apache.org/dist/spark/spark-1.6.1/spark-1.6.1-bin-hadoop2.6.tgz

Then:

ls
STEP 5 — Extract Spark

Run:

tar xvf spark-1.6.1-bin-hadoop2.6.tgz

Wait until extraction finishes.

Then:

ls

You should see:

spark-1.6.1-bin-hadoop2.6
STEP 6 — Move Spark

First become administrator:

sudo su

Enter your Ubuntu password.

Now run:

mv /home/$SUDO_USER/Downloads/spark-1.6.1-bin-hadoop2.6 /usr/local/spark

If that command gives an error, use your actual username.

Find your username with:

whoami

For example, if it says:

nithya

then run:

mv /home/nithya/Downloads/spark-1.6.1-bin-hadoop2.6 /usr/local/spark

Check:

ls /usr/local/spark

You should see folders such as:

bin
conf
lib
sbin

Now leave root:

exit

The PDF places Spark under /usr/local/spark.

STEP 7 — Configure Spark

Run:

nano ~/.bashrc

Go to the very bottom.

Add:

export PATH=$PATH:/usr/local/spark/bin

This is the PATH configuration shown in your PDF.

Save:

Ctrl + O

Press:

Enter

Then:

Ctrl + X
STEP 8 — Reload Configuration

Run:

source ~/.bashrc

Now check:

echo $PATH

You should see:

/usr/local/spark/bin

somewhere in the output.

STEP 9 — Start Spark

Run:

spark-shell

Wait.

You should eventually see:

scala>

STOP HERE.

When you see:

scala>

Spark is running successfully.

STEP 10 — Exit Spark Temporarily

At:

scala>

type:

:quit

You will return to:

username@ubuntu:~$
STEP 11 — Create the Input File

Run:

nano input.txt

Paste this text from your PDF:

In as name to here them deny wise this.
As rapid woody my he me which.
Men but they fail shew just wish next put.
Led all visitor musical calling nor her.
Within coming figure sex things are.
Pretended concluded did repulsive education smallness yet yet described.
Had countryman his pressed shewing.
No gate dare rose he.
Eyes year if miss he as upon.

Save:

Ctrl + O

Press:

Enter

Then:

Ctrl + X

Check:

cat input.txt

You should see your input text.

This is the input used for the Word Count example in the PDF.

STEP 12 — Start Spark Again

Run:

spark-shell

Wait for:

scala>
STEP 13 — Read the Input File

At:

scala>

type:

val inputfile = sc.textFile("input.txt")

You should get something similar to:

inputfile: org.apache.spark.rdd.RDD[String]
STEP 14 — Perform Word Count

Now type this one complete line:

val counts = inputfile.flatMap(line => line.split(" ")).map(word => (word, 1)).reduceByKey(_ + _)

The PDF's Word Count uses flatMap, map, and reduceByKey.

STEP 15 — Display Word Count

Type:

counts.collect()

You should get an array containing results like:

(fail,1)
(Led,1)
(next,1)
(nor,1)
(rose,1)
STEP 16 — Save the Output

Now type:

counts.saveAsTextFile("output")

The PDF saves the result using saveAsTextFile("output").

Wait until it finishes.

STEP 17 — Exit Spark

Type:

:quit
STEP 18 — Open the Output Folder

Run:

cd output

Then:

ls

You should see:

_SUCCESS
part-00000
STEP 19 — Display Final Result

Run:

cat part-00000

🎉 This is your final Spark Word Count output.

-------------------------------------------------------------------------
Ex.10
Spark Mani 's
Spark

sudo apt update
sudo apt install default-jdk -y
sudo apt install scala -y
wget https://archive.apache.org/dist/spark/spark-3.5.7/spark-3.5.7-bin-hadoop3.tgz

tar -xzf spark-3.5.7-bin-hadoop3.tgz

sudo mv spark-3.5.7-bin-hadoop3 /usr/local/spark

echo 'export SPARK_HOME=/usr/local/spark' >> ~/.bashrc
echo 'export PATH=$PATH:$SPARK_HOME/bin' >> ~/.bashrc

source ~/.bashrc
ls /usr/local/spark
ls /usr/local/spark/bin
/usr/local/spark/bin/spark-shell

new terminal 
echo "apple mango apple mango apple" > input.txt

important step: Step 2: Create the input file
Only at the Ubuntu prompt, run:
echo "apple mango apple mango apple" > input.txt

Verify it:
cat input.txt

Expected output:
apple mango apple mango apple

Step 3: Start Spark again
spark-shell

Wait until you see scala>.
Step 4: Execute the Word Count program
Type these commands inside Spark, one at a time.
val input = sc.textFile("file:///home/vboxuser/input.txt")
val words = input.flatMap(line => line.split(" "))
val pairs = words.map(word => (word, 1))
val counts = pairs.reduceByKey(_ + _)
counts.collect().foreach(println)
counts.saveAsTextFile("file:///home/vboxuser/output")

—--------------------------------------------------------------------------

Ex. 11

Install cloudsim

https://github.com/Cloudslab/cloudsim/releases/tag/cloudsim-3.0.3

Install common-math

https://repo.maven.apache.org/maven2/org/apache/commons/commons-math3/3.6.1/

Eclipse -> Download

—-----------------------------------------------------------------------------------

Ex.12

Download CloudAnalyst for netbeans

https://sourceforge.net/projects/cloudanalystnetbeans/

Download Netbeans 17– from under Installers and Packages – windows x64 exe
← Back to timeline